diff options
Diffstat (limited to 'spec/ruby/core/rational')
25 files changed, 243 insertions, 236 deletions
diff --git a/spec/ruby/core/rational/ceil_spec.rb b/spec/ruby/core/rational/ceil_spec.rb index d5bdadf3b6..0464eab101 100644 --- a/spec/ruby/core/rational/ceil_spec.rb +++ b/spec/ruby/core/rational/ceil_spec.rb @@ -1,45 +1,48 @@ require_relative "../../spec_helper" +require_relative "../integer/shared/integer_ceil_precision" describe "Rational#ceil" do + context "with values equal to integers" do + it_behaves_like :integer_ceil_precision, :Rational + end + before do @rational = Rational(2200, 7) end describe "with no arguments (precision = 0)" do - it "returns an Integer" do - @rational.ceil.should be_kind_of(Integer) - end + it "returns the Integer value rounded toward positive infinity" do + @rational.ceil.should.eql? 315 - it "returns the truncated value toward positive infinity" do - @rational.ceil.should == 315 - Rational(1, 2).ceil.should == 1 - Rational(-1, 2).ceil.should == 0 + Rational(1, 2).ceil.should.eql? 1 + Rational(-1, 2).ceil.should.eql? 0 + Rational(1, 1).ceil.should.eql? 1 end end describe "with a precision < 0" do - it "returns an Integer" do - @rational.ceil(-2).should be_kind_of(Integer) - @rational.ceil(-1).should be_kind_of(Integer) - end + it "moves the rounding point n decimal places left, returning an Integer" do + @rational.ceil(-3).should.eql? 1000 + @rational.ceil(-2).should.eql? 400 + @rational.ceil(-1).should.eql? 320 - it "moves the truncation point n decimal places left" do - @rational.ceil(-3).should == 1000 - @rational.ceil(-2).should == 400 - @rational.ceil(-1).should == 320 + Rational(100, 2).ceil(-1).should.eql? 50 + Rational(100, 2).ceil(-2).should.eql? 100 + Rational(-100, 2).ceil(-1).should.eql?(-50) + Rational(-100, 2).ceil(-2).should.eql?(0) end end describe "with precision > 0" do - it "returns a Rational" do - @rational.ceil(1).should be_kind_of(Rational) - @rational.ceil(2).should be_kind_of(Rational) - end + it "moves the rounding point n decimal places right, returning a Rational" do + @rational.ceil(1).should.eql? Rational(3143, 10) + @rational.ceil(2).should.eql? Rational(31429, 100) + @rational.ceil(3).should.eql? Rational(157143, 500) - it "moves the truncation point n decimal places right" do - @rational.ceil(1).should == Rational(3143, 10) - @rational.ceil(2).should == Rational(31429, 100) - @rational.ceil(3).should == Rational(157143, 500) + Rational(100, 2).ceil(1).should.eql? Rational(50, 1) + Rational(100, 2).ceil(2).should.eql? Rational(50, 1) + Rational(-100, 2).ceil(1).should.eql? Rational(-50, 1) + Rational(-100, 2).ceil(2).should.eql? Rational(-50, 1) end end end diff --git a/spec/ruby/core/rational/comparison_spec.rb b/spec/ruby/core/rational/comparison_spec.rb index c9db60d5c7..482e904989 100644 --- a/spec/ruby/core/rational/comparison_spec.rb +++ b/spec/ruby/core/rational/comparison_spec.rb @@ -3,54 +3,54 @@ require_relative 'fixtures/rational' describe "Rational#<=> when passed a Rational object" do it "returns 1 when self is greater than the passed argument" do - (Rational(4, 4) <=> Rational(3, 4)).should equal(1) - (Rational(-3, 4) <=> Rational(-4, 4)).should equal(1) + (Rational(4, 4) <=> Rational(3, 4)).should.equal?(1) + (Rational(-3, 4) <=> Rational(-4, 4)).should.equal?(1) end it "returns 0 when self is equal to the passed argument" do - (Rational(4, 4) <=> Rational(4, 4)).should equal(0) - (Rational(-3, 4) <=> Rational(-3, 4)).should equal(0) + (Rational(4, 4) <=> Rational(4, 4)).should.equal?(0) + (Rational(-3, 4) <=> Rational(-3, 4)).should.equal?(0) end it "returns -1 when self is less than the passed argument" do - (Rational(3, 4) <=> Rational(4, 4)).should equal(-1) - (Rational(-4, 4) <=> Rational(-3, 4)).should equal(-1) + (Rational(3, 4) <=> Rational(4, 4)).should.equal?(-1) + (Rational(-4, 4) <=> Rational(-3, 4)).should.equal?(-1) end end describe "Rational#<=> when passed an Integer object" do it "returns 1 when self is greater than the passed argument" do - (Rational(4, 4) <=> 0).should equal(1) - (Rational(4, 4) <=> -10).should equal(1) - (Rational(-3, 4) <=> -1).should equal(1) + (Rational(4, 4) <=> 0).should.equal?(1) + (Rational(4, 4) <=> -10).should.equal?(1) + (Rational(-3, 4) <=> -1).should.equal?(1) end it "returns 0 when self is equal to the passed argument" do - (Rational(4, 4) <=> 1).should equal(0) - (Rational(-8, 4) <=> -2).should equal(0) + (Rational(4, 4) <=> 1).should.equal?(0) + (Rational(-8, 4) <=> -2).should.equal?(0) end it "returns -1 when self is less than the passed argument" do - (Rational(3, 4) <=> 1).should equal(-1) - (Rational(-4, 4) <=> 0).should equal(-1) + (Rational(3, 4) <=> 1).should.equal?(-1) + (Rational(-4, 4) <=> 0).should.equal?(-1) end end describe "Rational#<=> when passed a Float object" do it "returns 1 when self is greater than the passed argument" do - (Rational(4, 4) <=> 0.5).should equal(1) - (Rational(4, 4) <=> -1.5).should equal(1) - (Rational(-3, 4) <=> -0.8).should equal(1) + (Rational(4, 4) <=> 0.5).should.equal?(1) + (Rational(4, 4) <=> -1.5).should.equal?(1) + (Rational(-3, 4) <=> -0.8).should.equal?(1) end it "returns 0 when self is equal to the passed argument" do - (Rational(4, 4) <=> 1.0).should equal(0) - (Rational(-6, 4) <=> -1.5).should equal(0) + (Rational(4, 4) <=> 1.0).should.equal?(0) + (Rational(-6, 4) <=> -1.5).should.equal?(0) end it "returns -1 when self is less than the passed argument" do - (Rational(3, 4) <=> 1.2).should equal(-1) - (Rational(-4, 4) <=> 0.5).should equal(-1) + (Rational(3, 4) <=> 1.2).should.equal?(-1) + (Rational(-4, 4) <=> 0.5).should.equal?(-1) end end @@ -82,12 +82,12 @@ describe "Rational#<=> when passed an Object that responds to #coerce" do b = mock("numeric with failed #coerce") b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError) - -> { Rational(3, 4) <=> b }.should raise_error(RationalSpecs::CoerceError) + -> { Rational(3, 4) <=> b }.should.raise(RationalSpecs::CoerceError) end end describe "Rational#<=> when passed a non-Numeric Object that doesn't respond to #coerce" do it "returns nil" do - (Rational <=> mock("Object")).should be_nil + (Rational <=> mock("Object")).should == nil end end diff --git a/spec/ruby/core/rational/denominator_spec.rb b/spec/ruby/core/rational/denominator_spec.rb index 4687244893..ba6e936d60 100644 --- a/spec/ruby/core/rational/denominator_spec.rb +++ b/spec/ruby/core/rational/denominator_spec.rb @@ -2,8 +2,8 @@ require_relative "../../spec_helper" describe "Rational#denominator" do it "returns the denominator" do - Rational(3, 4).denominator.should equal(4) - Rational(3, -4).denominator.should equal(4) + Rational(3, 4).denominator.should.equal?(4) + Rational(3, -4).denominator.should.equal?(4) Rational(1, bignum_value).denominator.should == bignum_value end diff --git a/spec/ruby/core/rational/div_spec.rb b/spec/ruby/core/rational/div_spec.rb index d3adb9b536..a679663543 100644 --- a/spec/ruby/core/rational/div_spec.rb +++ b/spec/ruby/core/rational/div_spec.rb @@ -2,16 +2,16 @@ require_relative "../../spec_helper" describe "Rational#div" do it "returns an Integer" do - Rational(229, 21).div(82).should be_kind_of(Integer) + Rational(229, 21).div(82).should.is_a?(Integer) end it "raises an ArgumentError if passed more than one argument" do - -> { Rational(3, 4).div(2,3) }.should raise_error(ArgumentError) + -> { Rational(3, 4).div(2,3) }.should.raise(ArgumentError) end # See http://redmine.ruby-lang.org/issues/show/1648 it "raises a TypeError if passed a non-numeric argument" do - -> { Rational(3, 4).div([]) }.should raise_error(TypeError) + -> { Rational(3, 4).div([]) }.should.raise(TypeError) end end @@ -22,11 +22,11 @@ describe "Rational#div passed a Rational" do end it "raises a ZeroDivisionError when the argument has a numerator of 0" do - -> { Rational(3, 4).div(Rational(0, 3)) }.should raise_error(ZeroDivisionError) + -> { Rational(3, 4).div(Rational(0, 3)) }.should.raise(ZeroDivisionError) end it "raises a ZeroDivisionError when the argument has a numerator of 0.0" do - -> { Rational(3, 4).div(Rational(0.0, 3)) }.should raise_error(ZeroDivisionError) + -> { Rational(3, 4).div(Rational(0.0, 3)) }.should.raise(ZeroDivisionError) end end @@ -37,7 +37,7 @@ describe "Rational#div passed an Integer" do end it "raises a ZeroDivisionError when the argument is 0" do - -> { Rational(3, 4).div(0) }.should raise_error(ZeroDivisionError) + -> { Rational(3, 4).div(0) }.should.raise(ZeroDivisionError) end end @@ -49,6 +49,6 @@ describe "Rational#div passed a Float" do end it "raises a ZeroDivisionError when the argument is 0.0" do - -> { Rational(3, 4).div(0.0) }.should raise_error(ZeroDivisionError) + -> { Rational(3, 4).div(0.0) }.should.raise(ZeroDivisionError) end end diff --git a/spec/ruby/core/rational/divide_spec.rb b/spec/ruby/core/rational/divide_spec.rb index 8f5ca1fdec..c45d1fca2f 100644 --- a/spec/ruby/core/rational/divide_spec.rb +++ b/spec/ruby/core/rational/divide_spec.rb @@ -29,46 +29,46 @@ end describe "Rational#/ when passed an Integer" do it "returns self divided by other as a Rational" do - (Rational(3, 4) / 2).should eql(Rational(3, 8)) - (Rational(2, 4) / 2).should eql(Rational(1, 4)) - (Rational(6, 7) / -2).should eql(Rational(-3, 7)) + (Rational(3, 4) / 2).should.eql?(Rational(3, 8)) + (Rational(2, 4) / 2).should.eql?(Rational(1, 4)) + (Rational(6, 7) / -2).should.eql?(Rational(-3, 7)) end it "raises a ZeroDivisionError when passed 0" do - -> { Rational(3, 4) / 0 }.should raise_error(ZeroDivisionError) + -> { Rational(3, 4) / 0 }.should.raise(ZeroDivisionError) end end describe "Rational#/ when passed a Rational" do it "returns self divided by other as a Rational" do - (Rational(3, 4) / Rational(3, 4)).should eql(Rational(1, 1)) - (Rational(2, 4) / Rational(1, 4)).should eql(Rational(2, 1)) + (Rational(3, 4) / Rational(3, 4)).should.eql?(Rational(1, 1)) + (Rational(2, 4) / Rational(1, 4)).should.eql?(Rational(2, 1)) (Rational(2, 4) / 2).should == Rational(1, 4) (Rational(6, 7) / -2).should == Rational(-3, 7) end it "raises a ZeroDivisionError when passed a Rational with a numerator of 0" do - -> { Rational(3, 4) / Rational(0, 1) }.should raise_error(ZeroDivisionError) + -> { Rational(3, 4) / Rational(0, 1) }.should.raise(ZeroDivisionError) end end describe "Rational#/ when passed a Float" do it "returns self divided by other as a Float" do - (Rational(3, 4) / 0.75).should eql(1.0) - (Rational(3, 4) / 0.25).should eql(3.0) - (Rational(3, 4) / 0.3).should eql(2.5) + (Rational(3, 4) / 0.75).should.eql?(1.0) + (Rational(3, 4) / 0.25).should.eql?(3.0) + (Rational(3, 4) / 0.3).should.eql?(2.5) - (Rational(-3, 4) / 0.3).should eql(-2.5) - (Rational(3, -4) / 0.3).should eql(-2.5) - (Rational(3, 4) / -0.3).should eql(-2.5) + (Rational(-3, 4) / 0.3).should.eql?(-2.5) + (Rational(3, -4) / 0.3).should.eql?(-2.5) + (Rational(3, 4) / -0.3).should.eql?(-2.5) end it "returns infinity when passed 0" do - (Rational(3, 4) / 0.0).infinite?.should eql(1) - (Rational(-3, -4) / 0.0).infinite?.should eql(1) + (Rational(3, 4) / 0.0).infinite?.should.eql?(1) + (Rational(-3, -4) / 0.0).infinite?.should.eql?(1) - (Rational(-3, 4) / 0.0).infinite?.should eql(-1) - (Rational(3, -4) / 0.0).infinite?.should eql(-1) + (Rational(-3, 4) / 0.0).infinite?.should.eql?(-1) + (Rational(3, -4) / 0.0).infinite?.should.eql?(-1) end end diff --git a/spec/ruby/core/rational/divmod_spec.rb b/spec/ruby/core/rational/divmod_spec.rb index f0555294a3..68f8ecfd2d 100644 --- a/spec/ruby/core/rational/divmod_spec.rb +++ b/spec/ruby/core/rational/divmod_spec.rb @@ -2,41 +2,41 @@ require_relative "../../spec_helper" describe "Rational#divmod when passed a Rational" do it "returns the quotient as Integer and the remainder as Rational" do - Rational(7, 4).divmod(Rational(1, 2)).should eql([3, Rational(1, 4)]) - Rational(7, 4).divmod(Rational(-1, 2)).should eql([-4, Rational(-1, 4)]) - Rational(0, 4).divmod(Rational(4, 3)).should eql([0, Rational(0, 1)]) + Rational(7, 4).divmod(Rational(1, 2)).should.eql?([3, Rational(1, 4)]) + Rational(7, 4).divmod(Rational(-1, 2)).should.eql?([-4, Rational(-1, 4)]) + Rational(0, 4).divmod(Rational(4, 3)).should.eql?([0, Rational(0, 1)]) - Rational(bignum_value, 4).divmod(Rational(4, 3)).should eql([3458764513820540928, Rational(0, 1)]) + Rational(bignum_value, 4).divmod(Rational(4, 3)).should.eql?([3458764513820540928, Rational(0, 1)]) end it "raises a ZeroDivisionError when passed a Rational with a numerator of 0" do - -> { Rational(7, 4).divmod(Rational(0, 3)) }.should raise_error(ZeroDivisionError) + -> { Rational(7, 4).divmod(Rational(0, 3)) }.should.raise(ZeroDivisionError) end end describe "Rational#divmod when passed an Integer" do it "returns the quotient as Integer and the remainder as Rational" do - Rational(7, 4).divmod(2).should eql([0, Rational(7, 4)]) - Rational(7, 4).divmod(-2).should eql([-1, Rational(-1, 4)]) + Rational(7, 4).divmod(2).should.eql?([0, Rational(7, 4)]) + Rational(7, 4).divmod(-2).should.eql?([-1, Rational(-1, 4)]) - Rational(bignum_value, 4).divmod(3).should eql([1537228672809129301, Rational(1, 1)]) + Rational(bignum_value, 4).divmod(3).should.eql?([1537228672809129301, Rational(1, 1)]) end it "raises a ZeroDivisionError when passed 0" do - -> { Rational(7, 4).divmod(0) }.should raise_error(ZeroDivisionError) + -> { Rational(7, 4).divmod(0) }.should.raise(ZeroDivisionError) end end describe "Rational#divmod when passed a Float" do it "returns the quotient as Integer and the remainder as Float" do - Rational(7, 4).divmod(0.5).should eql([3, 0.25]) + Rational(7, 4).divmod(0.5).should.eql?([3, 0.25]) end it "returns the quotient as Integer and the remainder as Float" do - Rational(7, 4).divmod(-0.5).should eql([-4, -0.25]) + Rational(7, 4).divmod(-0.5).should.eql?([-4, -0.25]) end it "raises a ZeroDivisionError when passed 0" do - -> { Rational(7, 4).divmod(0.0) }.should raise_error(ZeroDivisionError) + -> { Rational(7, 4).divmod(0.0) }.should.raise(ZeroDivisionError) end end diff --git a/spec/ruby/core/rational/equal_value_spec.rb b/spec/ruby/core/rational/equal_value_spec.rb index ba40d29c3b..1dd077ea41 100644 --- a/spec/ruby/core/rational/equal_value_spec.rb +++ b/spec/ruby/core/rational/equal_value_spec.rb @@ -5,35 +5,35 @@ describe "Rational#==" do obj = mock("Object") obj.should_receive(:==).and_return(:result) - (Rational(3, 4) == obj).should_not be_false + (Rational(3, 4) == obj).should_not == false end end describe "Rational#== when passed a Rational" do it "returns true if self has the same numerator and denominator as the passed argument" do - (Rational(3, 4) == Rational(3, 4)).should be_true - (Rational(-3, -4) == Rational(3, 4)).should be_true - (Rational(-4, 5) == Rational(4, -5)).should be_true + (Rational(3, 4) == Rational(3, 4)).should == true + (Rational(-3, -4) == Rational(3, 4)).should == true + (Rational(-4, 5) == Rational(4, -5)).should == true - (Rational(bignum_value, 3) == Rational(bignum_value, 3)).should be_true - (Rational(-bignum_value, 3) == Rational(bignum_value, -3)).should be_true + (Rational(bignum_value, 3) == Rational(bignum_value, 3)).should == true + (Rational(-bignum_value, 3) == Rational(bignum_value, -3)).should == true end end describe "Rational#== when passed a Float" do it "converts self to a Float and compares it with the passed argument" do - (Rational(3, 4) == 0.75).should be_true - (Rational(4, 2) == 2.0).should be_true - (Rational(-4, 2) == -2.0).should be_true - (Rational(4, -2) == -2.0).should be_true + (Rational(3, 4) == 0.75).should == true + (Rational(4, 2) == 2.0).should == true + (Rational(-4, 2) == -2.0).should == true + (Rational(4, -2) == -2.0).should == true end end describe "Rational#== when passed an Integer" do it "returns true if self has the passed argument as numerator and a denominator of 1" do # Rational(x, y) reduces x and y automatically - (Rational(4, 2) == 2).should be_true - (Rational(-4, 2) == -2).should be_true - (Rational(4, -2) == -2).should be_true + (Rational(4, 2) == 2).should == true + (Rational(-4, 2) == -2).should == true + (Rational(4, -2) == -2).should == true end end diff --git a/spec/ruby/core/rational/exponent_spec.rb b/spec/ruby/core/rational/exponent_spec.rb index 65fbf2ed1c..88b4a43796 100644 --- a/spec/ruby/core/rational/exponent_spec.rb +++ b/spec/ruby/core/rational/exponent_spec.rb @@ -5,20 +5,20 @@ describe "Rational#**" do # Guard against the Mathn library guard -> { !defined?(Math.rsqrt) } do it "returns Rational(1) if the exponent is Rational(0)" do - (Rational(0) ** Rational(0)).should eql(Rational(1)) - (Rational(1) ** Rational(0)).should eql(Rational(1)) - (Rational(3, 4) ** Rational(0)).should eql(Rational(1)) - (Rational(-1) ** Rational(0)).should eql(Rational(1)) - (Rational(-3, 4) ** Rational(0)).should eql(Rational(1)) - (Rational(bignum_value) ** Rational(0)).should eql(Rational(1)) - (Rational(-bignum_value) ** Rational(0)).should eql(Rational(1)) + (Rational(0) ** Rational(0)).should.eql?(Rational(1)) + (Rational(1) ** Rational(0)).should.eql?(Rational(1)) + (Rational(3, 4) ** Rational(0)).should.eql?(Rational(1)) + (Rational(-1) ** Rational(0)).should.eql?(Rational(1)) + (Rational(-3, 4) ** Rational(0)).should.eql?(Rational(1)) + (Rational(bignum_value) ** Rational(0)).should.eql?(Rational(1)) + (Rational(-bignum_value) ** Rational(0)).should.eql?(Rational(1)) end it "returns self raised to the argument as a Rational if the exponent's denominator is 1" do - (Rational(3, 4) ** Rational(1, 1)).should eql(Rational(3, 4)) - (Rational(3, 4) ** Rational(2, 1)).should eql(Rational(9, 16)) - (Rational(3, 4) ** Rational(-1, 1)).should eql(Rational(4, 3)) - (Rational(3, 4) ** Rational(-2, 1)).should eql(Rational(16, 9)) + (Rational(3, 4) ** Rational(1, 1)).should.eql?(Rational(3, 4)) + (Rational(3, 4) ** Rational(2, 1)).should.eql?(Rational(9, 16)) + (Rational(3, 4) ** Rational(-1, 1)).should.eql?(Rational(4, 3)) + (Rational(3, 4) ** Rational(-2, 1)).should.eql?(Rational(16, 9)) end it "returns self raised to the argument as a Float if the exponent's denominator is not 1" do @@ -49,12 +49,12 @@ describe "Rational#**" do # Guard against the Mathn library guard -> { !defined?(Math.rsqrt) } do it "returns Rational(1, 1) when the passed argument is 0" do - (Rational(3, 4) ** 0).should eql(Rational(1, 1)) - (Rational(-3, 4) ** 0).should eql(Rational(1, 1)) - (Rational(3, -4) ** 0).should eql(Rational(1, 1)) + (Rational(3, 4) ** 0).should.eql?(Rational(1, 1)) + (Rational(-3, 4) ** 0).should.eql?(Rational(1, 1)) + (Rational(3, -4) ** 0).should.eql?(Rational(1, 1)) - (Rational(bignum_value, 4) ** 0).should eql(Rational(1, 1)) - (Rational(3, -bignum_value) ** 0).should eql(Rational(1, 1)) + (Rational(bignum_value, 4) ** 0).should.eql?(Rational(1, 1)) + (Rational(3, -bignum_value) ** 0).should.eql?(Rational(1, 1)) end end end @@ -62,26 +62,26 @@ describe "Rational#**" do describe "when passed Bignum" do # #5713 it "returns Rational(0) when self is Rational(0) and the exponent is positive" do - (Rational(0) ** bignum_value).should eql(Rational(0)) + (Rational(0) ** bignum_value).should.eql?(Rational(0)) end it "raises ZeroDivisionError when self is Rational(0) and the exponent is negative" do - -> { Rational(0) ** -bignum_value }.should raise_error(ZeroDivisionError) + -> { Rational(0) ** -bignum_value }.should.raise(ZeroDivisionError) end it "returns Rational(1) when self is Rational(1)" do - (Rational(1) ** bignum_value).should eql(Rational(1)) - (Rational(1) ** -bignum_value).should eql(Rational(1)) + (Rational(1) ** bignum_value).should.eql?(Rational(1)) + (Rational(1) ** -bignum_value).should.eql?(Rational(1)) end it "returns Rational(1) when self is Rational(-1) and the exponent is positive and even" do - (Rational(-1) ** bignum_value(0)).should eql(Rational(1)) - (Rational(-1) ** bignum_value(2)).should eql(Rational(1)) + (Rational(-1) ** bignum_value(0)).should.eql?(Rational(1)) + (Rational(-1) ** bignum_value(2)).should.eql?(Rational(1)) end it "returns Rational(-1) when self is Rational(-1) and the exponent is positive and odd" do - (Rational(-1) ** bignum_value(1)).should eql(Rational(-1)) - (Rational(-1) ** bignum_value(3)).should eql(Rational(-1)) + (Rational(-1) ** bignum_value(1)).should.eql?(Rational(-1)) + (Rational(-1) ** bignum_value(3)).should.eql?(Rational(-1)) end ruby_version_is ""..."3.4" do @@ -96,10 +96,10 @@ describe "Rational#**" do it "returns 0.0 when self is > 1 and the exponent is negative" do -> { - (Rational(2) ** -bignum_value).should eql(0.0) + (Rational(2) ** -bignum_value).should.eql?(0.0) }.should complain(/warning: in a\*\*b, b may be too big/) -> { - (Rational(fixnum_max) ** -bignum_value).should eql(0.0) + (Rational(fixnum_max) ** -bignum_value).should.eql?(0.0) }.should complain(/warning: in a\*\*b, b may be too big/) end end @@ -108,37 +108,37 @@ describe "Rational#**" do it "raises an ArgumentError when self is > 1" do -> { (Rational(2) ** bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") -> { (Rational(fixnum_max) ** bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") end it "raises an ArgumentError when self is > 1 and the exponent is negative" do -> { (Rational(2) ** -bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") -> { (Rational(fixnum_max) ** -bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") end it "raises an ArgumentError when self is < -1" do -> { (Rational(-2) ** bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") -> { (Rational(fixnum_min) ** bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") end it "raises an ArgumentError when self is < -1 and the exponent is negative" do -> { (Rational(-2) ** -bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") -> { (Rational(fixnum_min) ** -bignum_value) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError, "exponent is too large") end end @@ -159,10 +159,10 @@ describe "Rational#**" do it "returns 0.0 when self is < -1 and the exponent is negative" do -> { - (Rational(-2) ** -bignum_value).should eql(0.0) + (Rational(-2) ** -bignum_value).should.eql?(0.0) }.should complain(/warning: in a\*\*b, b may be too big/) -> { - (Rational(fixnum_min) ** -bignum_value).should eql(0.0) + (Rational(fixnum_min) ** -bignum_value).should.eql?(0.0) }.should complain(/warning: in a\*\*b, b may be too big/) end end @@ -171,7 +171,7 @@ describe "Rational#**" do describe "when passed Float" do it "returns self converted to Float and raised to the passed argument" do - (Rational(3, 1) ** 3.0).should eql(27.0) + (Rational(3, 1) ** 3.0).should.eql?(27.0) (Rational(3, 1) ** 1.5).should be_close(5.19615242270663, TOLERANCE) (Rational(3, 1) ** -1.5).should be_close(0.192450089729875, TOLERANCE) end @@ -213,19 +213,19 @@ describe "Rational#**" do it "raises ZeroDivisionError for Rational(0, 1) passed a negative Integer" do [-1, -4, -9999].each do |exponent| - -> { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0") + -> { Rational(0, 1) ** exponent }.should.raise(ZeroDivisionError, "divided by 0") end end it "raises ZeroDivisionError for Rational(0, 1) passed a negative Rational with denominator 1" do [Rational(-1, 1), Rational(-3, 1)].each do |exponent| - -> { Rational(0, 1) ** exponent }.should raise_error(ZeroDivisionError, "divided by 0") + -> { Rational(0, 1) ** exponent }.should.raise(ZeroDivisionError, "divided by 0") end end # #7513 it "raises ZeroDivisionError for Rational(0, 1) passed a negative Rational" do - -> { Rational(0, 1) ** Rational(-3, 2) }.should raise_error(ZeroDivisionError, "divided by 0") + -> { Rational(0, 1) ** Rational(-3, 2) }.should.raise(ZeroDivisionError, "divided by 0") end it "returns Infinity for Rational(0, 1) passed a negative Float" do diff --git a/spec/ruby/core/rational/floor_spec.rb b/spec/ruby/core/rational/floor_spec.rb index 8068aaf119..6d4cee79a9 100644 --- a/spec/ruby/core/rational/floor_spec.rb +++ b/spec/ruby/core/rational/floor_spec.rb @@ -1,45 +1,49 @@ require_relative "../../spec_helper" +require_relative "../integer/shared/integer_floor_precision" describe "Rational#floor" do + context "with values equal to integers" do + it_behaves_like :integer_floor_precision, :Rational + end + before do @rational = Rational(2200, 7) end describe "with no arguments (precision = 0)" do - it "returns an integer" do - @rational.floor.should be_kind_of(Integer) - end - it "returns the truncated value toward negative infinity" do - @rational.floor.should == 314 - Rational(1, 2).floor.should == 0 - Rational(-1, 2).floor.should == -1 + it "returns the Integer value rounded toward negative infinity" do + @rational.floor.should.eql? 314 + + Rational(1, 2).floor.should.eql? 0 + Rational(-1, 2).floor.should.eql?(-1) + Rational(1, 1).floor.should.eql? 1 end end describe "with a precision < 0" do - it "returns an integer" do - @rational.floor(-2).should be_kind_of(Integer) - @rational.floor(-1).should be_kind_of(Integer) - end + it "moves the rounding point n decimal places left, returning an Integer" do + @rational.floor(-3).should.eql? 0 + @rational.floor(-2).should.eql? 300 + @rational.floor(-1).should.eql? 310 - it "moves the truncation point n decimal places left" do - @rational.floor(-3).should == 0 - @rational.floor(-2).should == 300 - @rational.floor(-1).should == 310 + Rational(100, 2).floor(-1).should.eql? 50 + Rational(100, 2).floor(-2).should.eql? 0 + Rational(-100, 2).floor(-1).should.eql?(-50) + Rational(-100, 2).floor(-2).should.eql?(-100) end end describe "with a precision > 0" do - it "returns a Rational" do - @rational.floor(1).should be_kind_of(Rational) - @rational.floor(2).should be_kind_of(Rational) - end + it "moves the rounding point n decimal places right, returning a Rational" do + @rational.floor(1).should.eql? Rational(1571, 5) + @rational.floor(2).should.eql? Rational(7857, 25) + @rational.floor(3).should.eql? Rational(62857, 200) - it "moves the truncation point n decimal places right" do - @rational.floor(1).should == Rational(1571, 5) - @rational.floor(2).should == Rational(7857, 25) - @rational.floor(3).should == Rational(62857, 200) + Rational(100, 2).floor(1).should.eql? Rational(50, 1) + Rational(100, 2).floor(2).should.eql? Rational(50, 1) + Rational(-100, 2).floor(1).should.eql? Rational(-50, 1) + Rational(-100, 2).floor(2).should.eql? Rational(-50, 1) end end end diff --git a/spec/ruby/core/rational/integer_spec.rb b/spec/ruby/core/rational/integer_spec.rb index be7476a9dd..cd7fa97fcf 100644 --- a/spec/ruby/core/rational/integer_spec.rb +++ b/spec/ruby/core/rational/integer_spec.rb @@ -3,11 +3,11 @@ describe "Rational#integer?" do # Guard against the Mathn library guard -> { !defined?(Math.rsqrt) } do it "returns false for a rational with a numerator and no denominator" do - Rational(20).integer?.should be_false + Rational(20).integer?.should == false end end it "returns false for a rational with a numerator and a denominator" do - Rational(20,3).integer?.should be_false + Rational(20,3).integer?.should == false end end diff --git a/spec/ruby/core/rational/marshal_dump_spec.rb b/spec/ruby/core/rational/marshal_dump_spec.rb index 17a6107cd5..06bf36f166 100644 --- a/spec/ruby/core/rational/marshal_dump_spec.rb +++ b/spec/ruby/core/rational/marshal_dump_spec.rb @@ -2,7 +2,7 @@ require_relative '../../spec_helper' describe "Rational#marshal_dump" do it "is a private method" do - Rational.should have_private_instance_method(:marshal_dump, false) + Rational.private_instance_methods(false).should.include?(:marshal_dump) end it "dumps numerator and denominator" do diff --git a/spec/ruby/core/rational/minus_spec.rb b/spec/ruby/core/rational/minus_spec.rb index 8aee85f9dd..4e10e118b9 100644 --- a/spec/ruby/core/rational/minus_spec.rb +++ b/spec/ruby/core/rational/minus_spec.rb @@ -29,23 +29,23 @@ end describe "Rational#- passed a Rational" do it "returns the result of subtracting other from self as a Rational" do - (Rational(3, 4) - Rational(0, 1)).should eql(Rational(3, 4)) - (Rational(3, 4) - Rational(1, 4)).should eql(Rational(1, 2)) + (Rational(3, 4) - Rational(0, 1)).should.eql?(Rational(3, 4)) + (Rational(3, 4) - Rational(1, 4)).should.eql?(Rational(1, 2)) - (Rational(3, 4) - Rational(2, 1)).should eql(Rational(-5, 4)) + (Rational(3, 4) - Rational(2, 1)).should.eql?(Rational(-5, 4)) end end describe "Rational#- passed a Float" do it "returns the result of subtracting other from self as a Float" do - (Rational(3, 4) - 0.2).should eql(0.55) - (Rational(3, 4) - 2.5).should eql(-1.75) + (Rational(3, 4) - 0.2).should.eql?(0.55) + (Rational(3, 4) - 2.5).should.eql?(-1.75) end end describe "Rational#- passed an Integer" do it "returns the result of subtracting other from self as a Rational" do - (Rational(3, 4) - 1).should eql(Rational(-1, 4)) - (Rational(3, 4) - 2).should eql(Rational(-5, 4)) + (Rational(3, 4) - 1).should.eql?(Rational(-1, 4)) + (Rational(3, 4) - 2).should.eql?(Rational(-5, 4)) end end diff --git a/spec/ruby/core/rational/modulo_spec.rb b/spec/ruby/core/rational/modulo_spec.rb index 23ed93e118..6241077f68 100644 --- a/spec/ruby/core/rational/modulo_spec.rb +++ b/spec/ruby/core/rational/modulo_spec.rb @@ -16,7 +16,7 @@ describe "Rational#%" do end it "returns a Float value when the argument is Float" do - (Rational(7, 4) % 1.0).should be_kind_of(Float) + (Rational(7, 4) % 1.0).should.is_a?(Float) (Rational(7, 4) % 1.0).should == 0.75 (Rational(7, 4) % 0.26).should be_close(0.19, 0.0001) end @@ -24,20 +24,20 @@ describe "Rational#%" do it "raises ZeroDivisionError on zero denominator" do -> { Rational(3, 5) % Rational(0, 1) - }.should raise_error(ZeroDivisionError) + }.should.raise(ZeroDivisionError) -> { Rational(0, 1) % Rational(0, 1) - }.should raise_error(ZeroDivisionError) + }.should.raise(ZeroDivisionError) -> { Rational(3, 5) % 0 - }.should raise_error(ZeroDivisionError) + }.should.raise(ZeroDivisionError) end it "raises a ZeroDivisionError when the argument is 0.0" do -> { Rational(3, 5) % 0.0 - }.should raise_error(ZeroDivisionError) + }.should.raise(ZeroDivisionError) end end diff --git a/spec/ruby/core/rational/multiply_spec.rb b/spec/ruby/core/rational/multiply_spec.rb index 87fb4de2b4..3e059cbc1c 100644 --- a/spec/ruby/core/rational/multiply_spec.rb +++ b/spec/ruby/core/rational/multiply_spec.rb @@ -29,37 +29,37 @@ end describe "Rational#* passed a Rational" do it "returns self divided by other as a Rational" do - (Rational(3, 4) * Rational(3, 4)).should eql(Rational(9, 16)) - (Rational(2, 4) * Rational(1, 4)).should eql(Rational(1, 8)) + (Rational(3, 4) * Rational(3, 4)).should.eql?(Rational(9, 16)) + (Rational(2, 4) * Rational(1, 4)).should.eql?(Rational(1, 8)) - (Rational(3, 4) * Rational(0, 1)).should eql(Rational(0, 4)) + (Rational(3, 4) * Rational(0, 1)).should.eql?(Rational(0, 4)) end end describe "Rational#* passed a Float" do it "returns self divided by other as a Float" do - (Rational(3, 4) * 0.75).should eql(0.5625) - (Rational(3, 4) * 0.25).should eql(0.1875) + (Rational(3, 4) * 0.75).should.eql?(0.5625) + (Rational(3, 4) * 0.25).should.eql?(0.1875) (Rational(3, 4) * 0.3).should be_close(0.225, TOLERANCE) (Rational(-3, 4) * 0.3).should be_close(-0.225, TOLERANCE) (Rational(3, -4) * 0.3).should be_close(-0.225, TOLERANCE) (Rational(3, 4) * -0.3).should be_close(-0.225, TOLERANCE) - (Rational(3, 4) * 0.0).should eql(0.0) - (Rational(-3, -4) * 0.0).should eql(0.0) + (Rational(3, 4) * 0.0).should.eql?(0.0) + (Rational(-3, -4) * 0.0).should.eql?(0.0) - (Rational(-3, 4) * 0.0).should eql(0.0) - (Rational(3, -4) * 0.0).should eql(0.0) + (Rational(-3, 4) * 0.0).should.eql?(0.0) + (Rational(3, -4) * 0.0).should.eql?(0.0) end end describe "Rational#* passed an Integer" do it "returns self divided by other as a Rational" do - (Rational(3, 4) * 2).should eql(Rational(3, 2)) - (Rational(2, 4) * 2).should eql(Rational(1, 1)) - (Rational(6, 7) * -2).should eql(Rational(-12, 7)) + (Rational(3, 4) * 2).should.eql?(Rational(3, 2)) + (Rational(2, 4) * 2).should.eql?(Rational(1, 1)) + (Rational(6, 7) * -2).should.eql?(Rational(-12, 7)) - (Rational(3, 4) * 0).should eql(Rational(0, 4)) + (Rational(3, 4) * 0).should.eql?(Rational(0, 4)) end end diff --git a/spec/ruby/core/rational/numerator_spec.rb b/spec/ruby/core/rational/numerator_spec.rb index 2b9fe2ff5c..631bb4703c 100644 --- a/spec/ruby/core/rational/numerator_spec.rb +++ b/spec/ruby/core/rational/numerator_spec.rb @@ -2,8 +2,8 @@ require_relative "../../spec_helper" describe "Rational#numerator" do it "returns the numerator" do - Rational(3, 4).numerator.should equal(3) - Rational(3, -4).numerator.should equal(-3) + Rational(3, 4).numerator.should.equal?(3) + Rational(3, -4).numerator.should.equal?(-3) Rational(bignum_value, 1).numerator.should == bignum_value end diff --git a/spec/ruby/core/rational/plus_spec.rb b/spec/ruby/core/rational/plus_spec.rb index 01df5f6719..92f830a105 100644 --- a/spec/ruby/core/rational/plus_spec.rb +++ b/spec/ruby/core/rational/plus_spec.rb @@ -29,22 +29,22 @@ end describe "Rational#+ with a Rational" do it "returns the result of subtracting other from self as a Rational" do - (Rational(3, 4) + Rational(0, 1)).should eql(Rational(3, 4)) - (Rational(3, 4) + Rational(1, 4)).should eql(Rational(1, 1)) + (Rational(3, 4) + Rational(0, 1)).should.eql?(Rational(3, 4)) + (Rational(3, 4) + Rational(1, 4)).should.eql?(Rational(1, 1)) - (Rational(3, 4) + Rational(2, 1)).should eql(Rational(11, 4)) + (Rational(3, 4) + Rational(2, 1)).should.eql?(Rational(11, 4)) end end describe "Rational#+ with a Float" do it "returns the result of subtracting other from self as a Float" do - (Rational(3, 4) + 0.2).should eql(0.95) - (Rational(3, 4) + 2.5).should eql(3.25) + (Rational(3, 4) + 0.2).should.eql?(0.95) + (Rational(3, 4) + 2.5).should.eql?(3.25) end end describe "Rational#+ with an Integer" do it "returns the result of subtracting other from self as a Rational" do - (Rational(3, 4) + 1).should eql(Rational(7, 4)) - (Rational(3, 4) + 2).should eql(Rational(11, 4)) + (Rational(3, 4) + 1).should.eql?(Rational(7, 4)) + (Rational(3, 4) + 2).should.eql?(Rational(11, 4)) end end diff --git a/spec/ruby/core/rational/rational_spec.rb b/spec/ruby/core/rational/rational_spec.rb index 482deab38d..278c4116a4 100644 --- a/spec/ruby/core/rational/rational_spec.rb +++ b/spec/ruby/core/rational/rational_spec.rb @@ -6,6 +6,6 @@ describe "Rational" do end it "does not respond to new" do - -> { Rational.new(1) }.should raise_error(NoMethodError) + -> { Rational.new(1) }.should.raise(NoMethodError) end end diff --git a/spec/ruby/core/rational/rationalize_spec.rb b/spec/ruby/core/rational/rationalize_spec.rb index 3db027d446..9c86824ddd 100644 --- a/spec/ruby/core/rational/rationalize_spec.rb +++ b/spec/ruby/core/rational/rationalize_spec.rb @@ -30,7 +30,7 @@ describe "Rational#rationalize" do end it "raises ArgumentError when passed more than one argument" do - -> { Rational(1,1).rationalize(0.1, 0.1) }.should raise_error(ArgumentError) - -> { Rational(1,1).rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError) + -> { Rational(1,1).rationalize(0.1, 0.1) }.should.raise(ArgumentError) + -> { Rational(1,1).rationalize(0.1, 0.1, 2) }.should.raise(ArgumentError) end end diff --git a/spec/ruby/core/rational/round_spec.rb b/spec/ruby/core/rational/round_spec.rb index ac3dcafe7b..dd6f66f408 100644 --- a/spec/ruby/core/rational/round_spec.rb +++ b/spec/ruby/core/rational/round_spec.rb @@ -7,9 +7,9 @@ describe "Rational#round" do describe "with no arguments (precision = 0)" do it "returns an integer" do - @rational.round.should be_kind_of(Integer) - Rational(0, 1).round(0).should be_kind_of(Integer) - Rational(124, 1).round(0).should be_kind_of(Integer) + @rational.round.should.is_a?(Integer) + Rational(0, 1).round(0).should.is_a?(Integer) + Rational(124, 1).round(0).should.is_a?(Integer) end it "returns the truncated value toward the nearest integer" do @@ -30,10 +30,10 @@ describe "Rational#round" do describe "with a precision < 0" do it "returns an integer" do - @rational.round(-2).should be_kind_of(Integer) - @rational.round(-1).should be_kind_of(Integer) - Rational(0, 1).round(-1).should be_kind_of(Integer) - Rational(2, 1).round(-1).should be_kind_of(Integer) + @rational.round(-2).should.is_a?(Integer) + @rational.round(-1).should.is_a?(Integer) + Rational(0, 1).round(-1).should.is_a?(Integer) + Rational(2, 1).round(-1).should.is_a?(Integer) end it "moves the truncation point n decimal places left" do @@ -45,12 +45,12 @@ describe "Rational#round" do describe "with a precision > 0" do it "returns a Rational" do - @rational.round(1).should be_kind_of(Rational) - @rational.round(2).should be_kind_of(Rational) + @rational.round(1).should.is_a?(Rational) + @rational.round(2).should.is_a?(Rational) # Guard against the Mathn library guard -> { !defined?(Math.rsqrt) } do - Rational(0, 1).round(1).should be_kind_of(Rational) - Rational(2, 1).round(1).should be_kind_of(Rational) + Rational(0, 1).round(1).should.is_a?(Rational) + Rational(2, 1).round(1).should.is_a?(Rational) end end @@ -100,7 +100,7 @@ describe "Rational#round" do end it "raise for a non-existent round mode" do - -> { Rational(10, 4).round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense") + -> { Rational(10, 4).round(half: :nonsense) }.should.raise(ArgumentError, "invalid rounding mode: nonsense") end end end diff --git a/spec/ruby/core/rational/shared/arithmetic_exception_in_coerce.rb b/spec/ruby/core/rational/shared/arithmetic_exception_in_coerce.rb index f4cf70d147..e15169c912 100644 --- a/spec/ruby/core/rational/shared/arithmetic_exception_in_coerce.rb +++ b/spec/ruby/core/rational/shared/arithmetic_exception_in_coerce.rb @@ -6,6 +6,6 @@ describe :rational_arithmetic_exception_in_coerce, shared: true do b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError) # e.g. Rational(3, 4) + b - -> { Rational(3, 4).send(@method, b) }.should raise_error(RationalSpecs::CoerceError) + -> { Rational(3, 4).send(@method, b) }.should.raise(RationalSpecs::CoerceError) end end diff --git a/spec/ruby/core/rational/to_f_spec.rb b/spec/ruby/core/rational/to_f_spec.rb index d0da49d377..40e3f11c0c 100644 --- a/spec/ruby/core/rational/to_f_spec.rb +++ b/spec/ruby/core/rational/to_f_spec.rb @@ -2,10 +2,10 @@ require_relative "../../spec_helper" describe "Rational#to_f" do it "returns self converted to a Float" do - Rational(3, 4).to_f.should eql(0.75) - Rational(3, -4).to_f.should eql(-0.75) - Rational(-1, 4).to_f.should eql(-0.25) - Rational(-1, -4).to_f.should eql(0.25) + Rational(3, 4).to_f.should.eql?(0.75) + Rational(3, -4).to_f.should.eql?(-0.75) + Rational(-1, 4).to_f.should.eql?(-0.25) + Rational(-1, -4).to_f.should.eql?(0.25) end it "converts to a Float for large numerator and denominator" do diff --git a/spec/ruby/core/rational/to_i_spec.rb b/spec/ruby/core/rational/to_i_spec.rb index 520a380b2a..e61b1b6c3b 100644 --- a/spec/ruby/core/rational/to_i_spec.rb +++ b/spec/ruby/core/rational/to_i_spec.rb @@ -2,11 +2,11 @@ require_relative "../../spec_helper" describe "Rational#to_i" do it "converts self to an Integer by truncation" do - Rational(7, 4).to_i.should eql(1) - Rational(11, 4).to_i.should eql(2) + Rational(7, 4).to_i.should.eql?(1) + Rational(11, 4).to_i.should.eql?(2) end it "converts self to an Integer by truncation" do - Rational(-7, 4).to_i.should eql(-1) + Rational(-7, 4).to_i.should.eql?(-1) end end diff --git a/spec/ruby/core/rational/to_r_spec.rb b/spec/ruby/core/rational/to_r_spec.rb index 34f16d7890..eb6097f595 100644 --- a/spec/ruby/core/rational/to_r_spec.rb +++ b/spec/ruby/core/rational/to_r_spec.rb @@ -3,15 +3,15 @@ require_relative "../../spec_helper" describe "Rational#to_r" do it "returns self" do a = Rational(3, 4) - a.to_r.should equal(a) + a.to_r.should.equal?(a) a = Rational(bignum_value, 4) - a.to_r.should equal(a) + a.to_r.should.equal?(a) end it "raises TypeError trying to convert BasicObject" do obj = BasicObject.new - -> { Rational(obj) }.should raise_error(TypeError) + -> { Rational(obj) }.should.raise(TypeError) end it "works when a BasicObject has to_r" do @@ -21,6 +21,6 @@ describe "Rational#to_r" do it "fails when a BasicObject's to_r does not return a Rational" do obj = BasicObject.new; def obj.to_r; 1 end - -> { Rational(obj) }.should raise_error(TypeError) + -> { Rational(obj) }.should.raise(TypeError) end end diff --git a/spec/ruby/core/rational/truncate_spec.rb b/spec/ruby/core/rational/truncate_spec.rb index 728fca34ea..3614431a7f 100644 --- a/spec/ruby/core/rational/truncate_spec.rb +++ b/spec/ruby/core/rational/truncate_spec.rb @@ -7,7 +7,7 @@ describe "Rational#truncate" do describe "with no arguments (precision = 0)" do it "returns an integer" do - @rational.truncate.should be_kind_of(Integer) + @rational.truncate.should.is_a?(Integer) end it "returns the truncated value toward 0" do @@ -19,7 +19,7 @@ describe "Rational#truncate" do describe "with an explicit precision = 0" do it "returns an integer" do - @rational.truncate(0).should be_kind_of(Integer) + @rational.truncate(0).should.is_a?(Integer) end it "returns the truncated value toward 0" do @@ -31,8 +31,8 @@ describe "Rational#truncate" do describe "with a precision < 0" do it "returns an integer" do - @rational.truncate(-2).should be_kind_of(Integer) - @rational.truncate(-1).should be_kind_of(Integer) + @rational.truncate(-2).should.is_a?(Integer) + @rational.truncate(-1).should.is_a?(Integer) end it "moves the truncation point n decimal places left" do @@ -44,8 +44,8 @@ describe "Rational#truncate" do describe "with a precision > 0" do it "returns a Rational" do - @rational.truncate(1).should be_kind_of(Rational) - @rational.truncate(2).should be_kind_of(Rational) + @rational.truncate(1).should.is_a?(Rational) + @rational.truncate(2).should.is_a?(Rational) end it "moves the truncation point n decimal places right" do @@ -57,15 +57,15 @@ describe "Rational#truncate" do describe "with an invalid value for precision" do it "raises a TypeError" do - -> { @rational.truncate(nil) }.should raise_error(TypeError, "not an integer") - -> { @rational.truncate(1.0) }.should raise_error(TypeError, "not an integer") - -> { @rational.truncate('') }.should raise_error(TypeError, "not an integer") + -> { @rational.truncate(nil) }.should.raise(TypeError, "not an integer") + -> { @rational.truncate(1.0) }.should.raise(TypeError, "not an integer") + -> { @rational.truncate('') }.should.raise(TypeError, "not an integer") end it "does not call to_int on the argument" do object = Object.new object.should_not_receive(:to_int) - -> { @rational.truncate(object) }.should raise_error(TypeError, "not an integer") + -> { @rational.truncate(object) }.should.raise(TypeError, "not an integer") end end end diff --git a/spec/ruby/core/rational/zero_spec.rb b/spec/ruby/core/rational/zero_spec.rb index af7fb391ac..2e4f783d5c 100644 --- a/spec/ruby/core/rational/zero_spec.rb +++ b/spec/ruby/core/rational/zero_spec.rb @@ -1,14 +1,14 @@ require_relative "../../spec_helper" describe "Rational#zero?" do it "returns true if the numerator is 0" do - Rational(0,26).zero?.should be_true + Rational(0,26).zero?.should == true end it "returns true if the numerator is 0.0" do - Rational(0.0,26).zero?.should be_true + Rational(0.0,26).zero?.should == true end it "returns false if the numerator isn't 0" do - Rational(26).zero?.should be_false + Rational(26).zero?.should == false end end |
