1require_relative '../../spec_helper'
2require_relative 'fixtures/common'
3
4describe "Exception#==" do
5  it "returns true if both exceptions are the same object" do
6    e = ArgumentError.new
7    e.should == e
8  end
9
10  it "returns true if one exception is the dup'd copy of the other" do
11    e = ArgumentError.new
12    e.should == e.dup
13  end
14
15  it "returns true if both exceptions have the same class, no message, and no backtrace" do
16    RuntimeError.new.should == RuntimeError.new
17  end
18
19  it "returns true if both exceptions have the same class, the same message, and no backtrace" do
20    TypeError.new("message").should == TypeError.new("message")
21  end
22
23  it "returns true if both exceptions have the same class, the same message, and the same backtrace" do
24    one = TypeError.new("message")
25    one.set_backtrace [File.dirname(__FILE__)]
26    two = TypeError.new("message")
27    two.set_backtrace [File.dirname(__FILE__)]
28    one.should == two
29  end
30
31  it "returns false if the two exceptions inherit from Exception but have different classes" do
32    one = RuntimeError.new("message")
33    one.set_backtrace [File.dirname(__FILE__)]
34    one.should be_kind_of(Exception)
35    two = TypeError.new("message")
36    two.set_backtrace [File.dirname(__FILE__)]
37    two.should be_kind_of(Exception)
38    one.should_not == two
39  end
40
41  it "returns true if the two objects subclass Exception and have the same message and backtrace" do
42    one = ExceptionSpecs::UnExceptional.new
43    two = ExceptionSpecs::UnExceptional.new
44    one.message.should == two.message
45    two.backtrace.should == two.backtrace
46    one.should == two
47  end
48
49  it "returns false if the argument is not an Exception" do
50    ArgumentError.new.should_not == String.new
51  end
52
53  it "returns false if the two exceptions differ only in their backtrace" do
54    one = RuntimeError.new("message")
55    one.set_backtrace [File.dirname(__FILE__)]
56    two = RuntimeError.new("message")
57    two.set_backtrace nil
58    one.should_not == two
59  end
60
61  it "returns false if the two exceptions differ only in their message" do
62    one = RuntimeError.new("message")
63    one.set_backtrace [File.dirname(__FILE__)]
64    two = RuntimeError.new("message2")
65    two.set_backtrace [File.dirname(__FILE__)]
66    one.should_not == two
67  end
68end
69