diff options
Diffstat (limited to 'spec/ruby/core/integer/comparison_spec.rb')
| -rw-r--r-- | spec/ruby/core/integer/comparison_spec.rb | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/spec/ruby/core/integer/comparison_spec.rb b/spec/ruby/core/integer/comparison_spec.rb index 4cf1d7cdc7..cc5cbe2506 100644 --- a/spec/ruby/core/integer/comparison_spec.rb +++ b/spec/ruby/core/integer/comparison_spec.rb @@ -116,7 +116,7 @@ describe "Integer#<=>" do describe "with an Object" do before :each do @big = bignum_value - @num = mock("value for Bignum#<=>") + @num = mock("value for Integer#<=>") end it "calls #coerce on other" do @@ -124,33 +124,21 @@ describe "Integer#<=>" do @big <=> @num end - ruby_version_is ""..."2.5" do - it "returns nil if #coerce raises an exception" do - @num.should_receive(:coerce).with(@big).and_raise(RuntimeError) - lambda { - @result = (@big <=> @num) - }.should complain(/Numerical comparison operators will no more rescue exceptions/) - @result.should be_nil - end - end - - ruby_version_is "2.5" do - it "lets the exception go through if #coerce raises an exception" do - @num.should_receive(:coerce).with(@big).and_raise(RuntimeError.new("my error")) - lambda { - @big <=> @num - }.should raise_error(RuntimeError, "my error") - end + it "lets the exception go through if #coerce raises an exception" do + @num.should_receive(:coerce).with(@big).and_raise(RuntimeError.new("my error")) + -> { + @big <=> @num + }.should.raise(RuntimeError, "my error") end it "raises an exception if #coerce raises a non-StandardError exception" do @num.should_receive(:coerce).with(@big).and_raise(Exception) - lambda { @big <=> @num }.should raise_error(Exception) + -> { @big <=> @num }.should.raise(Exception) end it "returns nil if #coerce does not return an Array" do @num.should_receive(:coerce).with(@big).and_return(nil) - (@big <=> @num).should be_nil + (@big <=> @num).should == nil end it "returns -1 if the coerced value is larger" do @@ -169,12 +157,20 @@ describe "Integer#<=>" do end end + describe "with a Float" do + it "does not lose precision for values that don't fit in a double" do + (bignum_value(1) <=> bignum_value.to_f).should == 1 + (bignum_value <=> bignum_value.to_f).should == 0 + ((bignum_value - 1) <=> bignum_value.to_f).should == -1 + end + end + # The tests below are taken from matz's revision 23730 for Ruby trunk it "returns 1 when self is Infinity and other is a Bignum" do (infinity_value <=> Float::MAX.to_i*2).should == 1 end - it "returns -1 when self is negative and other is Infinty" do + it "returns -1 when self is negative and other is Infinity" do (-Float::MAX.to_i*2 <=> infinity_value).should == -1 end |
