summaryrefslogtreecommitdiff
path: root/spec/ruby/core/integer
diff options
context:
space:
mode:
authorAndrew Konchin <[email protected]>2025-06-02 19:34:54 +0300
committerBenoit Daloze <[email protected]>2025-06-02 21:54:48 +0200
commitd6aa1714fed3e8b5ee8bede00a8853c338ff6092 (patch)
treeea863a44d9026f74b9a07375f401c3e5d8cb4bf5 /spec/ruby/core/integer
parent685c8ca9af892f562f64b54dbee73bb9a1999b90 (diff)
Update to ruby/spec@4d2fc4d
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13495
Diffstat (limited to 'spec/ruby/core/integer')
-rw-r--r--spec/ruby/core/integer/divide_spec.rb17
-rw-r--r--spec/ruby/core/integer/minus_spec.rb17
-rw-r--r--spec/ruby/core/integer/plus_spec.rb17
3 files changed, 51 insertions, 0 deletions
diff --git a/spec/ruby/core/integer/divide_spec.rb b/spec/ruby/core/integer/divide_spec.rb
index 665f4d57be..0d5e16e986 100644
--- a/spec/ruby/core/integer/divide_spec.rb
+++ b/spec/ruby/core/integer/divide_spec.rb
@@ -106,4 +106,21 @@ describe "Integer#/" do
-> { @bignum / :symbol }.should raise_error(TypeError)
end
end
+
+ it "coerces the RHS and calls #coerce" do
+ obj = mock("integer plus")
+ obj.should_receive(:coerce).with(6).and_return([6, 3])
+ (6 / obj).should == 2
+ end
+
+ it "coerces the RHS and calls #coerce even if it's private" do
+ obj = Object.new
+ class << obj
+ private def coerce(n)
+ [n, 3]
+ end
+ end
+
+ (6 / obj).should == 2
+ end
end
diff --git a/spec/ruby/core/integer/minus_spec.rb b/spec/ruby/core/integer/minus_spec.rb
index aadf416a05..6072ba7c8b 100644
--- a/spec/ruby/core/integer/minus_spec.rb
+++ b/spec/ruby/core/integer/minus_spec.rb
@@ -40,4 +40,21 @@ describe "Integer#-" do
-> { @bignum - :symbol }.should raise_error(TypeError)
end
end
+
+ it "coerces the RHS and calls #coerce" do
+ obj = mock("integer plus")
+ obj.should_receive(:coerce).with(5).and_return([5, 10])
+ (5 - obj).should == -5
+ end
+
+ it "coerces the RHS and calls #coerce even if it's private" do
+ obj = Object.new
+ class << obj
+ private def coerce(n)
+ [n, 10]
+ end
+ end
+
+ (5 - obj).should == -5
+ end
end
diff --git a/spec/ruby/core/integer/plus_spec.rb b/spec/ruby/core/integer/plus_spec.rb
index d01a76ab58..38428e56c5 100644
--- a/spec/ruby/core/integer/plus_spec.rb
+++ b/spec/ruby/core/integer/plus_spec.rb
@@ -55,4 +55,21 @@ describe "Integer#+" do
RUBY
ruby_exe(code).should == "-1"
end
+
+ it "coerces the RHS and calls #coerce" do
+ obj = mock("integer plus")
+ obj.should_receive(:coerce).with(6).and_return([6, 3])
+ (6 + obj).should == 9
+ end
+
+ it "coerces the RHS and calls #coerce even if it's private" do
+ obj = Object.new
+ class << obj
+ private def coerce(n)
+ [n, 3]
+ end
+ end
+
+ (6 + obj).should == 9
+ end
end