Skip to content

Commit 49f44b1

Browse files
flavorjoneseregon
authored andcommitted
Add ruby specs for UnboundMethod#== with included/extended modules [Bug #21873]
https://bugs.ruby-lang.org/issues/21873
1 parent f486ee3 commit 49f44b1

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

spec/ruby/core/unboundmethod/equal_value_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535

3636
@method_one = UnboundMethodSpecs::Methods.instance_method(:one)
3737
@method_two = UnboundMethodSpecs::Methods.instance_method(:two)
38+
39+
@mixin = UnboundMethodSpecs::Mixin.instance_method(:mixin_method)
40+
@includer_base = UnboundMethodSpecs::IncluderBase.new.method(:mixin_method).unbind
41+
@includer_child = UnboundMethodSpecs::IncluderChild.new.method(:mixin_method).unbind
42+
@extender_base = UnboundMethodSpecs::ExtenderBase.method(:mixin_method).unbind
43+
@extender_child = UnboundMethodSpecs::ExtenderChild.method(:mixin_method).unbind
3844
end
3945

4046
it "returns true if objects refer to the same method" do
@@ -91,6 +97,30 @@
9197
(@includer == @includee).should == true
9298
end
9399

100+
ruby_version_is "4.1" do
101+
it "returns true if same method is present in an object through module inclusion" do
102+
(@mixin == @includer_base).should == true
103+
(@includer_base == @mixin).should == true
104+
105+
(@mixin == @includer_child).should == true
106+
(@includer_child == @mixin).should == true
107+
108+
(@includer_base == @includer_child).should == true
109+
(@includer_child == @includer_base).should == true
110+
end
111+
112+
it "returns true if same method is present in an object through module extension" do
113+
(@mixin == @extender_base).should == true
114+
(@extender_base == @mixin).should == true
115+
116+
(@mixin == @extender_child).should == true
117+
(@extender_child == @mixin).should == true
118+
119+
(@extender_base == @extender_child).should == true
120+
(@extender_child == @extender_base).should == true
121+
end
122+
end
123+
94124
it "returns false if both have same Module, same name, identical body but not the same" do
95125
class UnboundMethodSpecs::Methods
96126
def discard_1; :discard; end

spec/ruby/core/unboundmethod/fixtures/classes.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ class << self
8080
end
8181
end
8282

83+
module Mixin
84+
def mixin_method; end
85+
end
86+
87+
class IncluderBase
88+
include Mixin
89+
end
90+
91+
class IncluderChild < IncluderBase; end
92+
93+
class ExtenderBase
94+
extend Mixin
95+
end
96+
97+
class ExtenderChild < ExtenderBase; end
98+
8399
class A
84100
def baz(a, b)
85101
return [__FILE__, self.class]

0 commit comments

Comments
 (0)