diff options
Diffstat (limited to 'spec/ruby/core/numeric/quo_spec.rb')
| -rw-r--r-- | spec/ruby/core/numeric/quo_spec.rb | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/spec/ruby/core/numeric/quo_spec.rb b/spec/ruby/core/numeric/quo_spec.rb index 24c752aac1..66ff019231 100644 --- a/spec/ruby/core/numeric/quo_spec.rb +++ b/spec/ruby/core/numeric/quo_spec.rb @@ -1,14 +1,13 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) -require File.expand_path('../shared/quo', __FILE__) +require_relative '../../spec_helper' +require_relative 'fixtures/classes' describe "Numeric#quo" do it "returns the result of self divided by the given Integer as a Rational" do - 5.quo(2).should eql(Rational(5,2)) + 5.quo(2).should.eql?(Rational(5,2)) end it "returns the result of self divided by the given Float as a Float" do - 2.quo(2.5).should eql(0.8) + 2.quo(2.5).should.eql?(0.8) end it "returns the result of self divided by the given Bignum as a Float" do @@ -16,11 +15,11 @@ describe "Numeric#quo" do end it "raises a ZeroDivisionError when the given Integer is 0" do - lambda { 0.quo(0) }.should raise_error(ZeroDivisionError) - lambda { 10.quo(0) }.should raise_error(ZeroDivisionError) - lambda { -10.quo(0) }.should raise_error(ZeroDivisionError) - lambda { bignum_value.quo(0) }.should raise_error(ZeroDivisionError) - lambda { -bignum_value.quo(0) }.should raise_error(ZeroDivisionError) + -> { 0.quo(0) }.should.raise(ZeroDivisionError) + -> { 10.quo(0) }.should.raise(ZeroDivisionError) + -> { -10.quo(0) }.should.raise(ZeroDivisionError) + -> { bignum_value.quo(0) }.should.raise(ZeroDivisionError) + -> { (-bignum_value).quo(0) }.should.raise(ZeroDivisionError) end it "calls #to_r to convert the object to a Rational" do @@ -34,16 +33,16 @@ describe "Numeric#quo" do obj = NumericSpecs::Subclass.new obj.should_receive(:to_r).and_return(1) - lambda { obj.quo(19) }.should raise_error(TypeError) + -> { obj.quo(19) }.should.raise(TypeError) end it "raises a TypeError when given a non-Integer" do - lambda { + -> { (obj = mock('x')).should_not_receive(:to_int) 13.quo(obj) - }.should raise_error(TypeError) - lambda { 13.quo("10") }.should raise_error(TypeError) - lambda { 13.quo(:symbol) }.should raise_error(TypeError) + }.should.raise(TypeError) + -> { 13.quo("10") }.should.raise(TypeError) + -> { 13.quo(:symbol) }.should.raise(TypeError) end it "returns the result of calling self#/ with other" do @@ -52,4 +51,13 @@ describe "Numeric#quo" do obj.quo(19).should == 1.quo(20) end + + it "raises a ZeroDivisionError if the given argument is zero and not a Float" do + -> { 1.quo(0) }.should.raise(ZeroDivisionError) + end + + it "returns infinity if the given argument is zero and is a Float" do + (1.quo(0.0)).to_s.should == 'Infinity' + (-1.quo(0.0)).to_s.should == '-Infinity' + end end |
