diff options
| author | Mike Dalessio <mike@37signals.com> | 2026-02-10 09:21:22 -0500 |
|---|---|---|
| committer | Benoit Daloze <eregontp@gmail.com> | 2026-02-10 16:51:04 +0100 |
| commit | 49f44b1ddd0c0da2cb734d91a441c3bbaf11ecf0 (patch) | |
| tree | a610fe77afa1178ffc611c70a18b3759807e1f11 /spec/ruby | |
| parent | f486ee340289b779654fe2d6c1de5a348fd76d86 (diff) | |
Add ruby specs for UnboundMethod#== with included/extended modules [Bug #21873]
https://bugs.ruby-lang.org/issues/21873
Diffstat (limited to 'spec/ruby')
| -rw-r--r-- | spec/ruby/core/unboundmethod/equal_value_spec.rb | 30 | ||||
| -rw-r--r-- | spec/ruby/core/unboundmethod/fixtures/classes.rb | 16 |
2 files changed, 46 insertions, 0 deletions
diff --git a/spec/ruby/core/unboundmethod/equal_value_spec.rb b/spec/ruby/core/unboundmethod/equal_value_spec.rb index c9f7ad45da..c2982766e9 100644 --- a/spec/ruby/core/unboundmethod/equal_value_spec.rb +++ b/spec/ruby/core/unboundmethod/equal_value_spec.rb @@ -35,6 +35,12 @@ describe "UnboundMethod#==" do @method_one = UnboundMethodSpecs::Methods.instance_method(:one) @method_two = UnboundMethodSpecs::Methods.instance_method(:two) + + @mixin = UnboundMethodSpecs::Mixin.instance_method(:mixin_method) + @includer_base = UnboundMethodSpecs::IncluderBase.new.method(:mixin_method).unbind + @includer_child = UnboundMethodSpecs::IncluderChild.new.method(:mixin_method).unbind + @extender_base = UnboundMethodSpecs::ExtenderBase.method(:mixin_method).unbind + @extender_child = UnboundMethodSpecs::ExtenderChild.method(:mixin_method).unbind end it "returns true if objects refer to the same method" do @@ -91,6 +97,30 @@ describe "UnboundMethod#==" do (@includer == @includee).should == true end + ruby_version_is "4.1" do + it "returns true if same method is present in an object through module inclusion" do + (@mixin == @includer_base).should == true + (@includer_base == @mixin).should == true + + (@mixin == @includer_child).should == true + (@includer_child == @mixin).should == true + + (@includer_base == @includer_child).should == true + (@includer_child == @includer_base).should == true + end + + it "returns true if same method is present in an object through module extension" do + (@mixin == @extender_base).should == true + (@extender_base == @mixin).should == true + + (@mixin == @extender_child).should == true + (@extender_child == @mixin).should == true + + (@extender_base == @extender_child).should == true + (@extender_child == @extender_base).should == true + end + end + it "returns false if both have same Module, same name, identical body but not the same" do class UnboundMethodSpecs::Methods def discard_1; :discard; end diff --git a/spec/ruby/core/unboundmethod/fixtures/classes.rb b/spec/ruby/core/unboundmethod/fixtures/classes.rb index 28d8e0a965..bb3f7e0849 100644 --- a/spec/ruby/core/unboundmethod/fixtures/classes.rb +++ b/spec/ruby/core/unboundmethod/fixtures/classes.rb @@ -80,6 +80,22 @@ module UnboundMethodSpecs end end + module Mixin + def mixin_method; end + end + + class IncluderBase + include Mixin + end + + class IncluderChild < IncluderBase; end + + class ExtenderBase + extend Mixin + end + + class ExtenderChild < ExtenderBase; end + class A def baz(a, b) return [__FILE__, self.class] |
