diff options
Diffstat (limited to 'spec/ruby/core/integer')
-rw-r--r-- | spec/ruby/core/integer/bit_and_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/core/integer/bit_or_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/core/integer/bit_xor_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/integer/ceildiv_spec.rb | 22 | ||||
-rw-r--r-- | spec/ruby/core/integer/try_convert_spec.rb | 12 |
5 files changed, 39 insertions, 7 deletions
diff --git a/spec/ruby/core/integer/bit_and_spec.rb b/spec/ruby/core/integer/bit_and_spec.rb index 8de5a14aaa..e7face39ac 100644 --- a/spec/ruby/core/integer/bit_and_spec.rb +++ b/spec/ruby/core/integer/bit_and_spec.rb @@ -30,7 +30,7 @@ describe "Integer#&" do it "coerces the rhs and calls #coerce" do obj = mock("fixnum bit and") - obj.should_receive(:coerce).with(6).and_return([3, 6]) + obj.should_receive(:coerce).with(6).and_return([6, 3]) (6 & obj).should == 2 end diff --git a/spec/ruby/core/integer/bit_or_spec.rb b/spec/ruby/core/integer/bit_or_spec.rb index 6f4279c170..fdf8a191e5 100644 --- a/spec/ruby/core/integer/bit_or_spec.rb +++ b/spec/ruby/core/integer/bit_or_spec.rb @@ -30,9 +30,9 @@ describe "Integer#|" do end it "coerces the rhs and calls #coerce" do - obj = mock("fixnum bit and") - obj.should_receive(:coerce).with(6).and_return([3, 6]) - (6 & obj).should == 2 + obj = mock("fixnum bit or") + obj.should_receive(:coerce).with(6).and_return([6, 3]) + (6 | obj).should == 7 end it "raises a TypeError when passed a Float" do diff --git a/spec/ruby/core/integer/bit_xor_spec.rb b/spec/ruby/core/integer/bit_xor_spec.rb index f1150a20d5..1f46bc52f3 100644 --- a/spec/ruby/core/integer/bit_xor_spec.rb +++ b/spec/ruby/core/integer/bit_xor_spec.rb @@ -28,8 +28,8 @@ describe "Integer#^" do end it "coerces the rhs and calls #coerce" do - obj = mock("fixnum bit and") - obj.should_receive(:coerce).with(6).and_return([3, 6]) + obj = mock("fixnum bit xor") + obj.should_receive(:coerce).with(6).and_return([6, 3]) (6 ^ obj).should == 5 end diff --git a/spec/ruby/core/integer/ceildiv_spec.rb b/spec/ruby/core/integer/ceildiv_spec.rb new file mode 100644 index 0000000000..18d07c66d0 --- /dev/null +++ b/spec/ruby/core/integer/ceildiv_spec.rb @@ -0,0 +1,22 @@ +require_relative '../../spec_helper' + +describe "Integer#ceildiv" do + ruby_version_is '3.2' do + it "returns a quotient of division which is rounded up to the nearest integer" do + 0.ceildiv(3).should eql(0) + 1.ceildiv(3).should eql(1) + 3.ceildiv(3).should eql(1) + 4.ceildiv(3).should eql(2) + + 4.ceildiv(-3).should eql(-1) + -4.ceildiv(3).should eql(-1) + -4.ceildiv(-3).should eql(2) + + 3.ceildiv(1.2).should eql(3) + 3.ceildiv(6/5r).should eql(3) + + (10**100-11).ceildiv(10**99-1).should eql(10) + (10**100-9).ceildiv(10**99-1).should eql(11) + end + end +end diff --git a/spec/ruby/core/integer/try_convert_spec.rb b/spec/ruby/core/integer/try_convert_spec.rb index 45c66eec79..4bc7d3851a 100644 --- a/spec/ruby/core/integer/try_convert_spec.rb +++ b/spec/ruby/core/integer/try_convert_spec.rb @@ -28,7 +28,17 @@ ruby_version_is "3.1" do it "sends #to_int to the argument and raises TypeError if it's not a kind of Integer" do obj = mock("to_int") obj.should_receive(:to_int).and_return(Object.new) - -> { Integer.try_convert obj }.should raise_error(TypeError) + -> { + Integer.try_convert obj + }.should raise_error(TypeError, "can't convert MockObject to Integer (MockObject#to_int gives Object)") + end + + it "responds with a different error message when it raises a TypeError, depending on the type of the non-Integer object :to_int returns" do + obj = mock("to_int") + obj.should_receive(:to_int).and_return("A String") + -> { + Integer.try_convert obj + }.should raise_error(TypeError, "can't convert MockObject to Integer (MockObject#to_int gives String)") end it "does not rescue exceptions raised by #to_int" do |