32
32
( @a == @b ) . should be_false
33
33
end
34
34
35
- ruby_version_is "" ..."1.9" do
36
- it "returns nil if calling #<=> on self returns nil" do
37
- @a . should_receive ( :<=> ) . any_number_of_times . and_return ( nil )
38
- ( @a == @b ) . should be_nil
39
- end
40
-
41
- it "returns nil if calling #<=> on self returns a non-Integer" do
42
- @a . should_receive ( :<=> ) . any_number_of_times . and_return ( "abc" )
43
- ( @a == @b ) . should be_nil
44
- end
35
+ it "returns nil if calling #<=> on self returns nil" do
36
+ @a . should_receive ( :<=> ) . any_number_of_times . and_return ( nil )
37
+ ( @a == @b ) . should be_nil
45
38
end
46
39
47
- ruby_version_is "1.9" do
48
- it "returns false if calling #<=> on self returns nil" do
49
- @a . should_receive ( :<=> ) . any_number_of_times . and_return ( nil )
50
- ( @a == @b ) . should be_false
51
- end
52
-
53
- it "returns false if calling #<=> on self returns a non-Integer" do
54
- @a . should_receive ( :<=> ) . any_number_of_times . and_return ( "abc" )
55
- ( @a == @b ) . should be_false
56
- end
40
+ it "returns nil if calling #<=> on self returns a non-Integer" do
41
+ @a . should_receive ( :<=> ) . any_number_of_times . and_return ( "abc" )
42
+ ( @a == @b ) . should be_nil
57
43
end
58
44
59
45
describe "when calling #<=> on self raises an Exception" do
@@ -73,19 +59,40 @@ def @raise_not_standard_error.<=>(b) raise SyntaxError, "test"; end
73
59
lambda { @raise_not_standard_error == @b } . should raise_error ( @not_standard_error )
74
60
end
75
61
76
- ruby_version_is "" ..."1.9" do
77
- it "returns nil if #<=> raises a StandardError" do
78
- ( @raise_standard_error == @b ) . should be_nil
79
- ( @raise_sub_standard_error == @b ) . should be_nil
80
- end
62
+ it "returns nil if #<=> raises a StandardError" do
63
+ ( @raise_standard_error == @b ) . should be_nil
64
+ ( @raise_sub_standard_error == @b ) . should be_nil
65
+ end
66
+ end
67
+
68
+ context "when #<=> is not defined" do
69
+ before :each do
70
+ @a = ComparableSpecs ::WithoutCompareDefined . new
71
+ @b = ComparableSpecs ::WithoutCompareDefined . new
72
+ end
73
+
74
+ it "returns true for identical objects" do
75
+ @a . should == @a
76
+ end
77
+
78
+ it "returns false and does not recurse infinitely" do
79
+ @a . should_not == @b
80
+ end
81
+ end
82
+
83
+ context "when #<=> calls super" do
84
+ before :each do
85
+ @a = ComparableSpecs ::CompareCallingSuper . new
86
+ @b = ComparableSpecs ::CompareCallingSuper . new
87
+ end
88
+
89
+ it "returns true for identical objects" do
90
+ @a . should == @a
81
91
end
82
92
83
- ruby_version_is "1.9" do
84
- # Behaviour confirmed by MRI test suite
85
- it "returns false if #<=> raises a StandardError" do
86
- ( @raise_standard_error == @b ) . should be_false
87
- ( @raise_sub_standard_error == @b ) . should be_false
88
- end
93
+ it "calls the defined #<=> only once for different objects" do
94
+ @a . should_not == @b
95
+ @a . calls . should == 1
89
96
end
90
97
end
91
- end
98
+ end
0 commit comments