1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2019-07-27 12:40:09 +02:00
parent a06301b103
commit 5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions

View file

@ -28,12 +28,12 @@ ruby_version_is '2.5' do
end
it "raises a TypeError when given a non-Integer" do
lambda {
-> {
(obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10])
13.allbits?(obj)
}.should raise_error(TypeError)
lambda { 13.allbits?("10") }.should raise_error(TypeError)
lambda { 13.allbits?(:symbol) }.should raise_error(TypeError)
-> { 13.allbits?("10") }.should raise_error(TypeError)
-> { 13.allbits?(:symbol) }.should raise_error(TypeError)
end
end
end

View file

@ -27,12 +27,12 @@ ruby_version_is '2.5' do
end
it "raises a TypeError when given a non-Integer" do
lambda {
-> {
(obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10])
13.anybits?(obj)
}.should raise_error(TypeError)
lambda { 13.anybits?("10") }.should raise_error(TypeError)
lambda { 13.anybits?(:symbol) }.should raise_error(TypeError)
-> { 13.anybits?("10") }.should raise_error(TypeError)
-> { 13.anybits?(:symbol) }.should raise_error(TypeError)
end
end
end

View file

@ -35,14 +35,14 @@ describe "Integer#&" do
end
it "raises a TypeError when passed a Float" do
lambda { (3 & 3.4) }.should raise_error(TypeError)
-> { (3 & 3.4) }.should raise_error(TypeError)
end
it "raises a TypeError and does not call #to_int when defined on an object" do
obj = mock("fixnum bit and")
obj.should_not_receive(:to_int)
lambda { 3 & obj }.should raise_error(TypeError)
-> { 3 & obj }.should raise_error(TypeError)
end
end
@ -84,14 +84,14 @@ describe "Integer#&" do
end
it "raises a TypeError when passed a Float" do
lambda { (@bignum & 3.4) }.should raise_error(TypeError)
-> { (@bignum & 3.4) }.should raise_error(TypeError)
end
it "raises a TypeError and does not call #to_int when defined on an object" do
obj = mock("bignum bit and")
obj.should_not_receive(:to_int)
lambda { @bignum & obj }.should raise_error(TypeError)
-> { @bignum & obj }.should raise_error(TypeError)
end
end
end

View file

@ -15,14 +15,14 @@ describe "Integer#|" do
end
it "raises a TypeError when passed a Float" do
lambda { (3 | 3.4) }.should raise_error(TypeError)
-> { (3 | 3.4) }.should raise_error(TypeError)
end
it "raises a TypeError and does not call #to_int when defined on an object" do
obj = mock("integer bit or")
obj.should_not_receive(:to_int)
lambda { 3 | obj }.should raise_error(TypeError)
-> { 3 | obj }.should raise_error(TypeError)
end
end
@ -51,18 +51,18 @@ describe "Integer#|" do
it "raises a TypeError when passed a Float" do
not_supported_on :opal do
lambda {
-> {
bignum_value | bignum_value(0xffff).to_f
}.should raise_error(TypeError)
end
lambda { @bignum | 9.9 }.should raise_error(TypeError)
-> { @bignum | 9.9 }.should raise_error(TypeError)
end
it "raises a TypeError and does not call #to_int when defined on an object" do
obj = mock("bignum bit or")
obj.should_not_receive(:to_int)
lambda { @bignum | obj }.should raise_error(TypeError)
-> { @bignum | obj }.should raise_error(TypeError)
end
end
end

View file

@ -13,14 +13,14 @@ describe "Integer#^" do
end
it "raises a TypeError when passed a Float" do
lambda { (3 ^ 3.4) }.should raise_error(TypeError)
-> { (3 ^ 3.4) }.should raise_error(TypeError)
end
it "raises a TypeError and does not call #to_int when defined on an object" do
obj = mock("integer bit xor")
obj.should_not_receive(:to_int)
lambda { 3 ^ obj }.should raise_error(TypeError)
-> { 3 ^ obj }.should raise_error(TypeError)
end
end
@ -55,18 +55,18 @@ describe "Integer#^" do
it "raises a TypeError when passed a Float" do
not_supported_on :opal do
lambda {
-> {
bignum_value ^ bignum_value(0xffff).to_f
}.should raise_error(TypeError)
end
lambda { @bignum ^ 14.5 }.should raise_error(TypeError)
-> { @bignum ^ 14.5 }.should raise_error(TypeError)
end
it "raises a TypeError and does not call #to_int when defined on an object" do
obj = mock("bignum bit xor")
obj.should_not_receive(:to_int)
lambda { @bignum ^ obj }.should raise_error(TypeError)
-> { @bignum ^ obj }.should raise_error(TypeError)
end
end
end

View file

@ -10,8 +10,8 @@ describe "Integer#chr without argument" do
end
it "raises a RangeError is self is less than 0" do
lambda { -1.chr }.should raise_error(RangeError)
lambda { -bignum_value.chr }.should raise_error(RangeError)
-> { -1.chr }.should raise_error(RangeError)
-> { -bignum_value.chr }.should raise_error(RangeError)
end
describe "when Encoding.default_internal is nil" do
@ -44,8 +44,8 @@ describe "Integer#chr without argument" do
end
it "raises a RangeError is self is greater than 255" do
lambda { 256.chr }.should raise_error(RangeError)
lambda { bignum_value.chr }.should raise_error(RangeError)
-> { 256.chr }.should raise_error(RangeError)
-> { bignum_value.chr }.should raise_error(RangeError)
end
end
@ -133,7 +133,7 @@ describe "Integer#chr without argument" do
[620, "TIS-620"]
].each do |integer, encoding_name|
Encoding.default_internal = Encoding.find(encoding_name)
lambda { integer.chr }.should raise_error(RangeError)
-> { integer.chr }.should raise_error(RangeError)
end
end
end
@ -150,7 +150,7 @@ describe "Integer#chr with an encoding argument" do
end
it "accepts a String as an argument" do
lambda { 0xA4A2.chr('euc-jp') }.should_not raise_error
-> { 0xA4A2.chr('euc-jp') }.should_not raise_error
end
it "converts a String to an Encoding as Encoding.find does" do
@ -161,12 +161,12 @@ describe "Integer#chr with an encoding argument" do
# http://redmine.ruby-lang.org/issues/4869
it "raises a RangeError is self is less than 0" do
lambda { -1.chr(Encoding::UTF_8) }.should raise_error(RangeError)
lambda { -bignum_value.chr(Encoding::EUC_JP) }.should raise_error(RangeError)
-> { -1.chr(Encoding::UTF_8) }.should raise_error(RangeError)
-> { -bignum_value.chr(Encoding::EUC_JP) }.should raise_error(RangeError)
end
it "raises a RangeError if self is too large" do
lambda { 2206368128.chr(Encoding::UTF_8) }.should raise_error(RangeError)
-> { 2206368128.chr(Encoding::UTF_8) }.should raise_error(RangeError)
end
it "returns a String with the specified encoding" do
@ -237,7 +237,7 @@ describe "Integer#chr with an encoding argument" do
[0xDC00, "UTF-16"],
[0xDFFF, "UTF-16"],
].each do |integer, encoding_name|
lambda { integer.chr(encoding_name) }.should raise_error(RangeError)
-> { integer.chr(encoding_name) }.should raise_error(RangeError)
end
end
end

View file

@ -1,5 +1,7 @@
require_relative '../../spec_helper'
require 'bigdecimal'
describe "Integer#coerce" do
context "fixnum" do
describe "when given a Fixnum" do
@ -11,7 +13,7 @@ describe "Integer#coerce" do
describe "when given a String" do
it "raises an ArgumentError when trying to coerce with a non-number String" do
lambda { 1.coerce(":)") }.should raise_error(ArgumentError)
-> { 1.coerce(":)") }.should raise_error(ArgumentError)
end
it "returns an array containing two Floats" do
@ -21,7 +23,7 @@ describe "Integer#coerce" do
end
it "raises a TypeError when trying to coerce with nil" do
lambda { 1.coerce(nil) }.should raise_error(TypeError)
-> { 1.coerce(nil) }.should raise_error(TypeError)
end
it "tries to convert the given Object into a Float by using #to_f" do
@ -29,13 +31,13 @@ describe "Integer#coerce" do
2.coerce(obj).should == [1.0, 2.0]
(obj = mock('0')).should_receive(:to_f).and_return('0')
lambda { 2.coerce(obj).should == [1.0, 2.0] }.should raise_error(TypeError)
-> { 2.coerce(obj).should == [1.0, 2.0] }.should raise_error(TypeError)
end
it "raises a TypeError when given an Object that does not respond to #to_f" do
lambda { 1.coerce(mock('x')) }.should raise_error(TypeError)
lambda { 1.coerce(1..4) }.should raise_error(TypeError)
lambda { 1.coerce(:test) }.should raise_error(TypeError)
-> { 1.coerce(mock('x')) }.should raise_error(TypeError)
-> { 1.coerce(1..4) }.should raise_error(TypeError)
-> { 1.coerce(:test) }.should raise_error(TypeError)
end
end
@ -62,10 +64,10 @@ describe "Integer#coerce" do
it "raises a TypeError when not passed a Fixnum or Bignum" do
a = bignum_value
lambda { a.coerce(nil) }.should raise_error(TypeError)
lambda { a.coerce(mock('str')) }.should raise_error(TypeError)
lambda { a.coerce(1..4) }.should raise_error(TypeError)
lambda { a.coerce(:test) }.should raise_error(TypeError)
-> { a.coerce(nil) }.should raise_error(TypeError)
-> { a.coerce(mock('str')) }.should raise_error(TypeError)
-> { a.coerce(1..4) }.should raise_error(TypeError)
-> { a.coerce(:test) }.should raise_error(TypeError)
end
it "coerces both values to Floats and returns [other, self] when passed a Float" do
@ -88,4 +90,15 @@ describe "Integer#coerce" do
ary.should == [1.2, a.to_f]
end
end
context "bigdecimal" do
it "produces Floats" do
x, y = 3.coerce(BigDecimal("3.4"))
x.class.should == Float
x.should == 3.4
y.class.should == Float
y.should == 3.0
end
end
end

View file

@ -127,7 +127,7 @@ describe "Integer#<=>" do
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
@ -137,7 +137,7 @@ describe "Integer#<=>" do
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
@ -145,7 +145,7 @@ describe "Integer#<=>" do
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_error(Exception)
end
it "returns nil if #coerce does not return an Array" do

View file

@ -19,14 +19,14 @@ describe "Integer#digits" do
end
it "raises ArgumentError when calling with a radix less than 2" do
lambda { 12345.digits(1) }.should raise_error(ArgumentError)
-> { 12345.digits(1) }.should raise_error(ArgumentError)
end
it "raises ArgumentError when calling with a negative radix" do
lambda { 12345.digits(-2) }.should raise_error(ArgumentError)
-> { 12345.digits(-2) }.should raise_error(ArgumentError)
end
it "raises Math::DomainError when calling digits on a negative number" do
lambda { -12345.digits(7) }.should raise_error(Math::DomainError)
-> { -12345.digits(7) }.should raise_error(Math::DomainError)
end
end

View file

@ -46,21 +46,21 @@ describe "Integer#div" do
end
it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
lambda { 0.div(0.0) }.should raise_error(ZeroDivisionError)
lambda { 10.div(0.0) }.should raise_error(ZeroDivisionError)
lambda { -10.div(0.0) }.should raise_error(ZeroDivisionError)
-> { 0.div(0.0) }.should raise_error(ZeroDivisionError)
-> { 10.div(0.0) }.should raise_error(ZeroDivisionError)
-> { -10.div(0.0) }.should raise_error(ZeroDivisionError)
end
it "raises a ZeroDivisionError when the given argument is 0 and not a Float" do
lambda { 13.div(0) }.should raise_error(ZeroDivisionError)
lambda { 13.div(-0) }.should raise_error(ZeroDivisionError)
-> { 13.div(0) }.should raise_error(ZeroDivisionError)
-> { 13.div(-0) }.should raise_error(ZeroDivisionError)
end
it "raises a TypeError when given a non-numeric argument" do
lambda { 13.div(mock('10')) }.should raise_error(TypeError)
lambda { 5.div("2") }.should raise_error(TypeError)
lambda { 5.div(:"2") }.should raise_error(TypeError)
lambda { 5.div([]) }.should raise_error(TypeError)
-> { 13.div(mock('10')) }.should raise_error(TypeError)
-> { 5.div("2") }.should raise_error(TypeError)
-> { 5.div(:"2") }.should raise_error(TypeError)
-> { 5.div([]) }.should raise_error(TypeError)
end
end
@ -118,9 +118,9 @@ describe "Integer#div" do
end
it "raises a TypeError when given a non-numeric" do
lambda { @bignum.div(mock("10")) }.should raise_error(TypeError)
lambda { @bignum.div("2") }.should raise_error(TypeError)
lambda { @bignum.div(:symbol) }.should raise_error(TypeError)
-> { @bignum.div(mock("10")) }.should raise_error(TypeError)
-> { @bignum.div("2") }.should raise_error(TypeError)
-> { @bignum.div(:symbol) }.should raise_error(TypeError)
end
it "returns a result of integer division of self by a float argument" do
@ -134,13 +134,13 @@ describe "Integer#div" do
# #5490
it "raises ZeroDivisionError if the argument is 0 and is a Float" do
lambda { @bignum.div(0.0) }.should raise_error(ZeroDivisionError)
lambda { @bignum.div(-0.0) }.should raise_error(ZeroDivisionError)
-> { @bignum.div(0.0) }.should raise_error(ZeroDivisionError)
-> { @bignum.div(-0.0) }.should raise_error(ZeroDivisionError)
end
it "raises ZeroDivisionError if the argument is 0 and is not a Float" do
lambda { @bignum.div(0) }.should raise_error(ZeroDivisionError)
lambda { @bignum.div(-0) }.should raise_error(ZeroDivisionError)
-> { @bignum.div(0) }.should raise_error(ZeroDivisionError)
-> { @bignum.div(-0) }.should raise_error(ZeroDivisionError)
end
end
end

View file

@ -27,7 +27,7 @@ describe "Integer#/" do
end
it "raises a ZeroDivisionError if the given argument is zero and not a Float" do
lambda { 1 / 0 }.should raise_error(ZeroDivisionError)
-> { 1 / 0 }.should raise_error(ZeroDivisionError)
end
it "does NOT raise ZeroDivisionError if the given argument is zero and is a Float" do
@ -41,9 +41,9 @@ describe "Integer#/" do
end
it "raises a TypeError when given a non-Integer" do
lambda { 13 / mock('10') }.should raise_error(TypeError)
lambda { 13 / "10" }.should raise_error(TypeError)
lambda { 13 / :symbol }.should raise_error(TypeError)
-> { 13 / mock('10') }.should raise_error(TypeError)
-> { 13 / "10" }.should raise_error(TypeError)
-> { 13 / :symbol }.should raise_error(TypeError)
end
end
@ -83,13 +83,13 @@ describe "Integer#/" do
end
it "raises a ZeroDivisionError if other is zero and not a Float" do
lambda { @bignum / 0 }.should raise_error(ZeroDivisionError)
-> { @bignum / 0 }.should raise_error(ZeroDivisionError)
end
it "raises a TypeError when given a non-numeric" do
lambda { @bignum / mock('10') }.should raise_error(TypeError)
lambda { @bignum / "2" }.should raise_error(TypeError)
lambda { @bignum / :symbol }.should raise_error(TypeError)
-> { @bignum / mock('10') }.should raise_error(TypeError)
-> { @bignum / "2" }.should raise_error(TypeError)
-> { @bignum / :symbol }.should raise_error(TypeError)
end
end
end

View file

@ -14,24 +14,24 @@ describe "Integer#divmod" do
end
it "raises a ZeroDivisionError when the given argument is 0" do
lambda { 13.divmod(0) }.should raise_error(ZeroDivisionError)
lambda { 0.divmod(0) }.should raise_error(ZeroDivisionError)
lambda { -10.divmod(0) }.should raise_error(ZeroDivisionError)
-> { 13.divmod(0) }.should raise_error(ZeroDivisionError)
-> { 0.divmod(0) }.should raise_error(ZeroDivisionError)
-> { -10.divmod(0) }.should raise_error(ZeroDivisionError)
end
it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
lambda { 0.divmod(0.0) }.should raise_error(ZeroDivisionError)
lambda { 10.divmod(0.0) }.should raise_error(ZeroDivisionError)
lambda { -10.divmod(0.0) }.should raise_error(ZeroDivisionError)
-> { 0.divmod(0.0) }.should raise_error(ZeroDivisionError)
-> { 10.divmod(0.0) }.should raise_error(ZeroDivisionError)
-> { -10.divmod(0.0) }.should raise_error(ZeroDivisionError)
end
it "raises a TypeError when given a non-Integer" do
lambda {
-> {
(obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
13.divmod(obj)
}.should raise_error(TypeError)
lambda { 13.divmod("10") }.should raise_error(TypeError)
lambda { 13.divmod(:symbol) }.should raise_error(TypeError)
-> { 13.divmod("10") }.should raise_error(TypeError)
-> { 13.divmod(:symbol) }.should raise_error(TypeError)
end
end
@ -94,24 +94,24 @@ describe "Integer#divmod" do
end
it "raises a ZeroDivisionError when the given argument is 0" do
lambda { @bignum.divmod(0) }.should raise_error(ZeroDivisionError)
lambda { (-@bignum).divmod(0) }.should raise_error(ZeroDivisionError)
-> { @bignum.divmod(0) }.should raise_error(ZeroDivisionError)
-> { (-@bignum).divmod(0) }.should raise_error(ZeroDivisionError)
end
# Behaviour established as correct in r23953
it "raises a FloatDomainError if other is NaN" do
lambda { @bignum.divmod(nan_value) }.should raise_error(FloatDomainError)
-> { @bignum.divmod(nan_value) }.should raise_error(FloatDomainError)
end
it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
lambda { @bignum.divmod(0.0) }.should raise_error(ZeroDivisionError)
lambda { (-@bignum).divmod(0.0) }.should raise_error(ZeroDivisionError)
-> { @bignum.divmod(0.0) }.should raise_error(ZeroDivisionError)
-> { (-@bignum).divmod(0.0) }.should raise_error(ZeroDivisionError)
end
it "raises a TypeError when the given argument is not an Integer" do
lambda { @bignum.divmod(mock('10')) }.should raise_error(TypeError)
lambda { @bignum.divmod("10") }.should raise_error(TypeError)
lambda { @bignum.divmod(:symbol) }.should raise_error(TypeError)
-> { @bignum.divmod(mock('10')) }.should raise_error(TypeError)
-> { @bignum.divmod("10") }.should raise_error(TypeError)
-> { @bignum.divmod(:symbol) }.should raise_error(TypeError)
end
end
end

View file

@ -27,8 +27,8 @@ describe "Integer#downto [stop] when self and stop are Fixnums" do
end
it "raises an ArgumentError for invalid endpoints" do
lambda {1.downto("A") {|x| p x } }.should raise_error(ArgumentError)
lambda {1.downto(nil) {|x| p x } }.should raise_error(ArgumentError)
-> {1.downto("A") {|x| p x } }.should raise_error(ArgumentError)
-> {1.downto(nil) {|x| p x } }.should raise_error(ArgumentError)
end
describe "when no block is given" do
@ -45,9 +45,9 @@ describe "Integer#downto [stop] when self and stop are Fixnums" do
describe "size" do
it "raises an ArgumentError for invalid endpoints" do
enum = 1.downto("A")
lambda { enum.size }.should raise_error(ArgumentError)
-> { enum.size }.should raise_error(ArgumentError)
enum = 1.downto(nil)
lambda { enum.size }.should raise_error(ArgumentError)
-> { enum.size }.should raise_error(ArgumentError)
end
it "returns self - stop + 1" do

View file

@ -59,13 +59,13 @@ describe "Integer#[]" do
end
it "raises a TypeError when passed a String" do
lambda { 3["3"] }.should raise_error(TypeError)
-> { 3["3"] }.should raise_error(TypeError)
end
it "raises a TypeError when #to_int does not return an Integer" do
obj = mock('asdf')
obj.should_receive(:to_int).and_return("asdf")
lambda { 3[obj] }.should raise_error(TypeError)
-> { 3[obj] }.should raise_error(TypeError)
end
it "calls #to_int to coerce a String to a Bignum and returns 0" do
@ -102,10 +102,10 @@ describe "Integer#[]" do
it "raises a TypeError when the given argument can't be converted to Integer" do
obj = mock('asdf')
lambda { @bignum[obj] }.should raise_error(TypeError)
-> { @bignum[obj] }.should raise_error(TypeError)
obj.should_receive(:to_int).and_return("asdf")
lambda { @bignum[obj] }.should raise_error(TypeError)
-> { @bignum[obj] }.should raise_error(TypeError)
end
end
end

View file

@ -35,11 +35,11 @@ describe "Integer#fdiv" do
end
it "raises a TypeError when argument isn't numeric" do
lambda { 1.fdiv(mock('non-numeric')) }.should raise_error(TypeError)
-> { 1.fdiv(mock('non-numeric')) }.should raise_error(TypeError)
end
it "raises an ArgumentError when passed multiple arguments" do
lambda { 1.fdiv(6,0.2) }.should raise_error(ArgumentError)
-> { 1.fdiv(6,0.2) }.should raise_error(ArgumentError)
end
it "follows the coercion protocol" do

View file

@ -55,15 +55,15 @@ describe "Integer#gcd" do
end
it "raises an ArgumentError if not given an argument" do
lambda { 12.gcd }.should raise_error(ArgumentError)
-> { 12.gcd }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if given more than one argument" do
lambda { 12.gcd(30, 20) }.should raise_error(ArgumentError)
-> { 12.gcd(30, 20) }.should raise_error(ArgumentError)
end
it "raises a TypeError unless the argument is an Integer" do
lambda { 39.gcd(3.8) }.should raise_error(TypeError)
lambda { 45872.gcd([]) }.should raise_error(TypeError)
-> { 39.gcd(3.8) }.should raise_error(TypeError)
-> { 45872.gcd([]) }.should raise_error(TypeError)
end
end

View file

@ -39,15 +39,15 @@ describe "Integer#gcdlcm" do
end
it "raises an ArgumentError if not given an argument" do
lambda { 12.gcdlcm }.should raise_error(ArgumentError)
-> { 12.gcdlcm }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if given more than one argument" do
lambda { 12.gcdlcm(30, 20) }.should raise_error(ArgumentError)
-> { 12.gcdlcm(30, 20) }.should raise_error(ArgumentError)
end
it "raises a TypeError unless the argument is an Integer" do
lambda { 39.gcdlcm(3.8) }.should raise_error(TypeError)
lambda { 45872.gcdlcm([]) }.should raise_error(TypeError)
-> { 39.gcdlcm(3.8) }.should raise_error(TypeError)
-> { 45872.gcdlcm([]) }.should raise_error(TypeError)
end
end

View file

@ -23,8 +23,8 @@ describe "Integer#>" do
end
it "raises an ArgumentError when given a non-Integer" do
lambda { 5 > "4" }.should raise_error(ArgumentError)
lambda { 5 > mock('x') }.should raise_error(ArgumentError)
-> { 5 > "4" }.should raise_error(ArgumentError)
-> { 5 > mock('x') }.should raise_error(ArgumentError)
end
end
@ -42,8 +42,8 @@ describe "Integer#>" do
end
it "raises an ArgumentError when given a non-Integer" do
lambda { @bignum > "4" }.should raise_error(ArgumentError)
lambda { @bignum > mock('str') }.should raise_error(ArgumentError)
-> { @bignum > "4" }.should raise_error(ArgumentError)
-> { @bignum > mock('str') }.should raise_error(ArgumentError)
end
end
end

View file

@ -24,8 +24,8 @@ describe "Integer#>=" do
end
it "raises an ArgumentError when given a non-Integer" do
lambda { 5 >= "4" }.should raise_error(ArgumentError)
lambda { 5 >= mock('x') }.should raise_error(ArgumentError)
-> { 5 >= "4" }.should raise_error(ArgumentError)
-> { 5 >= mock('x') }.should raise_error(ArgumentError)
end
end
@ -42,8 +42,8 @@ describe "Integer#>=" do
end
it "raises an ArgumentError when given a non-Integer" do
lambda { @bignum >= "4" }.should raise_error(ArgumentError)
lambda { @bignum >= mock('str') }.should raise_error(ArgumentError)
-> { @bignum >= "4" }.should raise_error(ArgumentError)
-> { @bignum >= mock('str') }.should raise_error(ArgumentError)
end
end
end

View file

@ -44,15 +44,15 @@ describe "Integer#lcm" do
end
it "raises an ArgumentError if not given an argument" do
lambda { 12.lcm }.should raise_error(ArgumentError)
-> { 12.lcm }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if given more than one argument" do
lambda { 12.lcm(30, 20) }.should raise_error(ArgumentError)
-> { 12.lcm(30, 20) }.should raise_error(ArgumentError)
end
it "raises a TypeError unless the argument is an Integer" do
lambda { 39.lcm(3.8) }.should raise_error(TypeError)
lambda { 45872.lcm([]) }.should raise_error(TypeError)
-> { 39.lcm(3.8) }.should raise_error(TypeError)
-> { 45872.lcm([]) }.should raise_error(TypeError)
end
end

View file

@ -79,15 +79,15 @@ describe "Integer#<< (with n << m)" do
obj = mock("a string")
obj.should_receive(:to_int).and_return("asdf")
lambda { 3 << obj }.should raise_error(TypeError)
-> { 3 << obj }.should raise_error(TypeError)
end
it "raises a TypeError when passed nil" do
lambda { 3 << nil }.should raise_error(TypeError)
-> { 3 << nil }.should raise_error(TypeError)
end
it "raises a TypeError when passed a String" do
lambda { 3 << "4" }.should raise_error(TypeError)
-> { 3 << "4" }.should raise_error(TypeError)
end
end
@ -151,15 +151,15 @@ describe "Integer#<< (with n << m)" do
obj = mock("a string")
obj.should_receive(:to_int).and_return("asdf")
lambda { @bignum << obj }.should raise_error(TypeError)
-> { @bignum << obj }.should raise_error(TypeError)
end
it "raises a TypeError when passed nil" do
lambda { @bignum << nil }.should raise_error(TypeError)
-> { @bignum << nil }.should raise_error(TypeError)
end
it "raises a TypeError when passed a String" do
lambda { @bignum << "4" }.should raise_error(TypeError)
-> { @bignum << "4" }.should raise_error(TypeError)
end
end
end

View file

@ -23,8 +23,8 @@ describe "Integer#<" do
end
it "raises an ArgumentError when given a non-Integer" do
lambda { 5 < "4" }.should raise_error(ArgumentError)
lambda { 5 < mock('x') }.should raise_error(ArgumentError)
-> { 5 < "4" }.should raise_error(ArgumentError)
-> { 5 < mock('x') }.should raise_error(ArgumentError)
end
end
@ -44,8 +44,8 @@ describe "Integer#<" do
end
it "raises an ArgumentError when given a non-Integer" do
lambda { @bignum < "4" }.should raise_error(ArgumentError)
lambda { @bignum < mock('str') }.should raise_error(ArgumentError)
-> { @bignum < "4" }.should raise_error(ArgumentError)
-> { @bignum < mock('str') }.should raise_error(ArgumentError)
end
end
end

View file

@ -24,8 +24,8 @@ describe "Integer#<=" do
end
it "raises an ArgumentError when given a non-Integer" do
lambda { 5 <= "4" }.should raise_error(ArgumentError)
lambda { 5 <= mock('x') }.should raise_error(ArgumentError)
-> { 5 <= "4" }.should raise_error(ArgumentError)
-> { 5 <= mock('x') }.should raise_error(ArgumentError)
end
end
@ -47,8 +47,8 @@ describe "Integer#<=" do
end
it "raises an ArgumentError when given a non-Integer" do
lambda { @bignum <= "4" }.should raise_error(ArgumentError)
lambda { @bignum <= mock('str') }.should raise_error(ArgumentError)
-> { @bignum <= "4" }.should raise_error(ArgumentError)
-> { @bignum <= mock('str') }.should raise_error(ArgumentError)
end
end
end

View file

@ -20,12 +20,12 @@ describe "Integer#-" do
end
it "raises a TypeError when given a non-Integer" do
lambda {
-> {
(obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
13 - obj
}.should raise_error(TypeError)
lambda { 13 - "10" }.should raise_error(TypeError)
lambda { 13 - :symbol }.should raise_error(TypeError)
-> { 13 - "10" }.should raise_error(TypeError)
-> { 13 - :symbol }.should raise_error(TypeError)
end
end
@ -41,9 +41,9 @@ describe "Integer#-" do
end
it "raises a TypeError when given a non-Integer" do
lambda { @bignum - mock('10') }.should raise_error(TypeError)
lambda { @bignum - "10" }.should raise_error(TypeError)
lambda { @bignum - :symbol }.should raise_error(TypeError)
-> { @bignum - mock('10') }.should raise_error(TypeError)
-> { @bignum - "10" }.should raise_error(TypeError)
-> { @bignum - :symbol }.should raise_error(TypeError)
end
end
end

View file

@ -21,12 +21,12 @@ describe "Integer#*" do
end
it "raises a TypeError when given a non-Integer" do
lambda {
-> {
(obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
13 * obj
}.should raise_error(TypeError)
lambda { 13 * "10" }.should raise_error(TypeError)
lambda { 13 * :symbol }.should raise_error(TypeError)
-> { 13 * "10" }.should raise_error(TypeError)
-> { 13 * :symbol }.should raise_error(TypeError)
end
end
@ -43,9 +43,9 @@ describe "Integer#*" do
end
it "raises a TypeError when given a non-Integer" do
lambda { @bignum * mock('10') }.should raise_error(TypeError)
lambda { @bignum * "10" }.should raise_error(TypeError)
lambda { @bignum * :symbol }.should raise_error(TypeError)
-> { @bignum * mock('10') }.should raise_error(TypeError)
-> { @bignum * "10" }.should raise_error(TypeError)
-> { @bignum * :symbol }.should raise_error(TypeError)
end
end
end

View file

@ -27,12 +27,12 @@ ruby_version_is '2.5' do
end
it "raises a TypeError when given a non-Integer" do
lambda {
-> {
(obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10])
13.nobits?(obj)
}.should raise_error(TypeError)
lambda { 13.nobits?("10") }.should raise_error(TypeError)
lambda { 13.nobits?(:symbol) }.should raise_error(TypeError)
-> { 13.nobits?("10") }.should raise_error(TypeError)
-> { 13.nobits?(:symbol) }.should raise_error(TypeError)
end
end
end

View file

@ -20,12 +20,12 @@ describe "Integer#+" do
end
it "raises a TypeError when given a non-Integer" do
lambda {
-> {
(obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
13 + obj
}.should raise_error(TypeError)
lambda { 13 + "10" }.should raise_error(TypeError)
lambda { 13 + :symbol }.should raise_error(TypeError)
-> { 13 + "10" }.should raise_error(TypeError)
-> { 13 + :symbol }.should raise_error(TypeError)
end
end
@ -41,9 +41,9 @@ describe "Integer#+" do
end
it "raises a TypeError when given a non-Integer" do
lambda { @bignum + mock('10') }.should raise_error(TypeError)
lambda { @bignum + "10" }.should raise_error(TypeError)
lambda { @bignum + :symbol}.should raise_error(TypeError)
-> { @bignum + mock('10') }.should raise_error(TypeError)
-> { @bignum + "10" }.should raise_error(TypeError)
-> { @bignum + :symbol}.should raise_error(TypeError)
end
end
end

View file

@ -33,7 +33,7 @@ describe "Integer#rationalize" do
end
it "raises ArgumentError when passed more than one argument" do
lambda { 1.rationalize(0.1, 0.1) }.should raise_error(ArgumentError)
lambda { 1.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError)
-> { 1.rationalize(0.1, 0.1) }.should raise_error(ArgumentError)
-> { 1.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError)
end
end

View file

@ -38,14 +38,14 @@ describe "Integer#remainder" do
end
it "raises a ZeroDivisionError if other is zero and not a Float" do
lambda { bignum_value(66).remainder(0) }.should raise_error(ZeroDivisionError)
-> { bignum_value(66).remainder(0) }.should raise_error(ZeroDivisionError)
end
it "does raises ZeroDivisionError if other is zero and a Float" do
a = bignum_value(7)
b = bignum_value(32)
lambda { a.remainder(0.0) }.should raise_error(ZeroDivisionError)
lambda { b.remainder(-0.0) }.should raise_error(ZeroDivisionError)
-> { a.remainder(0.0) }.should raise_error(ZeroDivisionError)
-> { b.remainder(-0.0) }.should raise_error(ZeroDivisionError)
end
end
end

View file

@ -79,15 +79,15 @@ describe "Integer#>> (with n >> m)" do
obj = mock("a string")
obj.should_receive(:to_int).and_return("asdf")
lambda { 3 >> obj }.should raise_error(TypeError)
-> { 3 >> obj }.should raise_error(TypeError)
end
it "raises a TypeError when passed nil" do
lambda { 3 >> nil }.should raise_error(TypeError)
-> { 3 >> nil }.should raise_error(TypeError)
end
it "raises a TypeError when passed a String" do
lambda { 3 >> "4" }.should raise_error(TypeError)
-> { 3 >> "4" }.should raise_error(TypeError)
end
end
@ -177,15 +177,15 @@ describe "Integer#>> (with n >> m)" do
obj = mock("a string")
obj.should_receive(:to_int).and_return("asdf")
lambda { @bignum >> obj }.should raise_error(TypeError)
-> { @bignum >> obj }.should raise_error(TypeError)
end
it "raises a TypeError when passed nil" do
lambda { @bignum >> nil }.should raise_error(TypeError)
-> { @bignum >> nil }.should raise_error(TypeError)
end
it "raises a TypeError when passed a String" do
lambda { @bignum >> "4" }.should raise_error(TypeError)
-> { @bignum >> "4" }.should raise_error(TypeError)
end
end
end

View file

@ -31,24 +31,24 @@ describe "Integer#round" do
platform_is_not wordsize: 32 do
it "raises a RangeError when passed a big negative value" do
lambda { 42.round(fixnum_min) }.should raise_error(RangeError)
-> { 42.round(fixnum_min) }.should raise_error(RangeError)
end
end
it "raises a RangeError when passed Float::INFINITY" do
lambda { 42.round(Float::INFINITY) }.should raise_error(RangeError)
-> { 42.round(Float::INFINITY) }.should raise_error(RangeError)
end
it "raises a RangeError when passed a beyond signed int" do
lambda { 42.round(1<<31) }.should raise_error(RangeError)
-> { 42.round(1<<31) }.should raise_error(RangeError)
end
it "raises a TypeError when passed a String" do
lambda { 42.round("4") }.should raise_error(TypeError)
-> { 42.round("4") }.should raise_error(TypeError)
end
it "raises a TypeError when its argument cannot be converted to an Integer" do
lambda { 42.round(nil) }.should raise_error(TypeError)
-> { 42.round(nil) }.should raise_error(TypeError)
end
it "calls #to_int on the argument to convert it to an Integer" do
@ -60,7 +60,7 @@ describe "Integer#round" do
it "raises a TypeError when #to_int does not return an Integer" do
obj = mock("Object")
obj.stub!(:to_int).and_return([])
lambda { 42.round(obj) }.should raise_error(TypeError)
-> { 42.round(obj) }.should raise_error(TypeError)
end
it "returns different rounded values depending on the half option" do
@ -95,7 +95,7 @@ describe "Integer#round" do
end
it "raises ArgumentError for an unknown rounding mode" do
lambda { 42.round(-1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/)
lambda { 42.round(1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/)
-> { 42.round(-1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/)
-> { 42.round(1, half: :foo) }.should raise_error(ArgumentError, /invalid rounding mode: foo/)
end
end

View file

@ -99,9 +99,9 @@ describe :integer_exponent, shared: true do
end
it "raises a TypeError when given a non-Integer" do
lambda { @bignum.send(@method, mock('10')) }.should raise_error(TypeError)
lambda { @bignum.send(@method, "10") }.should raise_error(TypeError)
lambda { @bignum.send(@method, :symbol) }.should raise_error(TypeError)
-> { @bignum.send(@method, mock('10')) }.should raise_error(TypeError)
-> { @bignum.send(@method, "10") }.should raise_error(TypeError)
-> { @bignum.send(@method, :symbol) }.should raise_error(TypeError)
end
it "switch to a Float when the values is too big" do

View file

@ -21,24 +21,24 @@ describe :integer_modulo, shared: true do
end
it "raises a ZeroDivisionError when the given argument is 0" do
lambda { 13.send(@method, 0) }.should raise_error(ZeroDivisionError)
lambda { 0.send(@method, 0) }.should raise_error(ZeroDivisionError)
lambda { -10.send(@method, 0) }.should raise_error(ZeroDivisionError)
-> { 13.send(@method, 0) }.should raise_error(ZeroDivisionError)
-> { 0.send(@method, 0) }.should raise_error(ZeroDivisionError)
-> { -10.send(@method, 0) }.should raise_error(ZeroDivisionError)
end
it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
lambda { 0.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
lambda { 10.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
lambda { -10.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
-> { 0.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
-> { 10.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
-> { -10.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
end
it "raises a TypeError when given a non-Integer" do
lambda {
-> {
(obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
13.send(@method, obj)
}.should raise_error(TypeError)
lambda { 13.send(@method, "10") }.should raise_error(TypeError)
lambda { 13.send(@method, :symbol) }.should raise_error(TypeError)
-> { 13.send(@method, "10") }.should raise_error(TypeError)
-> { 13.send(@method, :symbol) }.should raise_error(TypeError)
end
end
@ -56,19 +56,19 @@ describe :integer_modulo, shared: true do
end
it "raises a ZeroDivisionError when the given argument is 0" do
lambda { @bignum.send(@method, 0) }.should raise_error(ZeroDivisionError)
lambda { (-@bignum).send(@method, 0) }.should raise_error(ZeroDivisionError)
-> { @bignum.send(@method, 0) }.should raise_error(ZeroDivisionError)
-> { (-@bignum).send(@method, 0) }.should raise_error(ZeroDivisionError)
end
it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
lambda { @bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
lambda { -@bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
-> { @bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
-> { -@bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
end
it "raises a TypeError when given a non-Integer" do
lambda { @bignum.send(@method, mock('10')) }.should raise_error(TypeError)
lambda { @bignum.send(@method, "10") }.should raise_error(TypeError)
lambda { @bignum.send(@method, :symbol) }.should raise_error(TypeError)
-> { @bignum.send(@method, mock('10')) }.should raise_error(TypeError)
-> { @bignum.send(@method, "10") }.should raise_error(TypeError)
-> { @bignum.send(@method, :symbol) }.should raise_error(TypeError)
end
end
end

View file

@ -15,7 +15,7 @@ ruby_version_is "2.5" do
end
it "raises a Math::DomainError if the argument is negative" do
lambda { Integer.sqrt(-4) }.should raise_error(Math::DomainError)
-> { Integer.sqrt(-4) }.should raise_error(Math::DomainError)
end
it "accepts any argument that can be coerced to Integer" do
@ -27,7 +27,7 @@ ruby_version_is "2.5" do
end
it "raises a TypeError if the argument cannot be coerced to Integer" do
lambda { Integer.sqrt("test") }.should raise_error(TypeError)
-> { Integer.sqrt("test") }.should raise_error(TypeError)
end
end
end

View file

@ -20,7 +20,7 @@ describe "Integer#to_r" do
end
it "raises an ArgumentError if given any arguments" do
lambda { 287.to_r(2) }.should raise_error(ArgumentError)
lambda { 9102826.to_r(309, [], 71) }.should raise_error(ArgumentError)
-> { 287.to_r(2) }.should raise_error(ArgumentError)
-> { 9102826.to_r(309, [], 71) }.should raise_error(ArgumentError)
end
end

View file

@ -13,10 +13,10 @@ describe "Integer#to_s" do
end
it "raises an ArgumentError if the base is less than 2 or higher than 36" do
lambda { 123.to_s(-1) }.should raise_error(ArgumentError)
lambda { 123.to_s(0) }.should raise_error(ArgumentError)
lambda { 123.to_s(1) }.should raise_error(ArgumentError)
lambda { 123.to_s(37) }.should raise_error(ArgumentError)
-> { 123.to_s(-1) }.should raise_error(ArgumentError)
-> { 123.to_s(0) }.should raise_error(ArgumentError)
-> { 123.to_s(1) }.should raise_error(ArgumentError)
-> { 123.to_s(37) }.should raise_error(ArgumentError)
end
end
@ -59,10 +59,10 @@ describe "Integer#to_s" do
end
it "raises an ArgumentError if the base is less than 2 or higher than 36" do
lambda { 123.to_s(-1) }.should raise_error(ArgumentError)
lambda { 123.to_s(0) }.should raise_error(ArgumentError)
lambda { 123.to_s(1) }.should raise_error(ArgumentError)
lambda { 123.to_s(37) }.should raise_error(ArgumentError)
-> { 123.to_s(-1) }.should raise_error(ArgumentError)
-> { 123.to_s(0) }.should raise_error(ArgumentError)
-> { 123.to_s(1) }.should raise_error(ArgumentError)
-> { 123.to_s(37) }.should raise_error(ArgumentError)
end
end

View file

@ -27,8 +27,8 @@ describe "Integer#upto [stop] when self and stop are Fixnums" do
end
it "raises an ArgumentError for non-numeric endpoints" do
lambda { 1.upto("A") {|x| p x} }.should raise_error(ArgumentError)
lambda { 1.upto(nil) {|x| p x} }.should raise_error(ArgumentError)
-> { 1.upto("A") {|x| p x} }.should raise_error(ArgumentError)
-> { 1.upto(nil) {|x| p x} }.should raise_error(ArgumentError)
end
describe "when no block is given" do
@ -45,9 +45,9 @@ describe "Integer#upto [stop] when self and stop are Fixnums" do
describe "size" do
it "raises an ArgumentError for non-numeric endpoints" do
enum = 1.upto("A")
lambda { enum.size }.should raise_error(ArgumentError)
-> { enum.size }.should raise_error(ArgumentError)
enum = 1.upto(nil)
lambda { enum.size }.should raise_error(ArgumentError)
-> { enum.size }.should raise_error(ArgumentError)
end
it "returns stop - self + 1" do