diff options
Diffstat (limited to 'spec/ruby/core/numeric/coerce_spec.rb')
| -rw-r--r-- | spec/ruby/core/numeric/coerce_spec.rb | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/spec/ruby/core/numeric/coerce_spec.rb b/spec/ruby/core/numeric/coerce_spec.rb index 820d900dd5..9344d99ee6 100644 --- a/spec/ruby/core/numeric/coerce_spec.rb +++ b/spec/ruby/core/numeric/coerce_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) +require_relative '../../spec_helper' +require_relative 'fixtures/classes' describe "Numeric#coerce" do before :each do @@ -25,52 +25,35 @@ describe "Numeric#coerce" do class << a; true; end # watch it explode - lambda { a.coerce(b) }.should raise_error(TypeError) + -> { a.coerce(b) }.should.raise(TypeError) end end - it "calls #to_f to convert other if self responds to #to_f" do - # Do not use NumericSpecs::Subclass here, because coerce checks the classes of the receiver - # and arguments before calling #to_f. - other = mock("numeric") - lambda { @obj.coerce(other) }.should raise_error(TypeError) - end - it "returns [other.to_f, self.to_f] if self and other are instances of different classes" do - result = @obj.coerce(2.5) - result.should == [2.5, 10.5] - result.first.should be_kind_of(Float) - result.last.should be_kind_of(Float) - - result = @obj.coerce(3) - result.should == [3.0, 10.5] - result.first.should be_kind_of(Float) - result.last.should be_kind_of(Float) - - result = @obj.coerce("4.4") - result.should == [4.4, 10.5] - result.first.should be_kind_of(Float) - result.last.should be_kind_of(Float) + @obj.coerce(2.5).should == [2.5, 10.5] + @obj.coerce(3).should == [3.0, 10.5] + @obj.coerce("4.4").should == [4.4, 10.5] + @obj.coerce(bignum_value).should == [bignum_value.to_f, 10.5] + end - result = @obj.coerce(bignum_value) - result.should == [bignum_value.to_f, 10.5] - result.first.should be_kind_of(Float) - result.last.should be_kind_of(Float) + it "raise TypeError if they are instances of different classes and other does not respond to #to_f" do + other = mock("numeric") + -> { @obj.coerce(other) }.should.raise(TypeError) end it "raises a TypeError when passed nil" do - lambda { @obj.coerce(nil) }.should raise_error(TypeError) + -> { @obj.coerce(nil) }.should.raise(TypeError) end it "raises a TypeError when passed a boolean" do - lambda { @obj.coerce(false) }.should raise_error(TypeError) + -> { @obj.coerce(false) }.should.raise(TypeError) end it "raises a TypeError when passed a Symbol" do - lambda { @obj.coerce(:symbol) }.should raise_error(TypeError) + -> { @obj.coerce(:symbol) }.should.raise(TypeError) end - it "raises an ArgumentError when passed a String" do - lambda { @obj.coerce("test") }.should raise_error(ArgumentError) + it "raises an ArgumentError when passed a non-numeric String" do + -> { @obj.coerce("test") }.should.raise(ArgumentError) end end |
