Skip to content

Commit d3c94d1

Browse files
sampokuokkaneneregon
authored andcommitted
Add specs for Method#/UnboundMethod#original_name through a three-alias chain
Extend MethodSpecs::Methods and UnboundMethodSpecs::Methods with a third alias hop (alias qux baz), and add examples verifying that Method#original_name and UnboundMethod#original_name still return :foo when reached through three levels of aliasing. The existing "aliased twice" examples only exercise two-hop chains, which doesn't catch implementations that resolve a fixed depth rather than walking the full chain.
1 parent 990cdde commit d3c94d1

4 files changed

Lines changed: 14 additions & 0 deletions

File tree

core/method/fixtures/classes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def foo
2727

2828
alias bar foo
2929
alias baz bar
30+
alias qux baz
3031

3132
def same_as_foo
3233
true

core/method/original_name_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
obj.method(:baz).unbind.bind(obj).original_name.should == :foo
2121
end
2222

23+
it "returns the original name even when aliased thrice" do
24+
obj = MethodSpecs::Methods.new
25+
obj.method(:qux).original_name.should == :foo
26+
obj.method(:qux).unbind.bind(obj).original_name.should == :foo
27+
end
28+
2329
it "returns the source UnboundMethod's name (not the name given to define_method)" do
2430
klass = Class.new { define_method(:my_inspect, ::Kernel.instance_method(:inspect)) }
2531
klass.new.method(:my_inspect).original_name.should == :inspect

core/unboundmethod/fixtures/classes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def with_block(&block); end
3636

3737
alias bar foo
3838
alias baz bar
39+
alias qux baz
3940
alias alias_1 foo
4041
alias alias_2 foo
4142

core/unboundmethod/original_name_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
UnboundMethodSpecs::Methods.instance_method(:baz).original_name.should == :foo
2121
end
2222

23+
it "returns the original name even when aliased thrice" do
24+
obj = UnboundMethodSpecs::Methods.new
25+
obj.method(:qux).unbind.original_name.should == :foo
26+
UnboundMethodSpecs::Methods.instance_method(:qux).original_name.should == :foo
27+
end
28+
2329
it "returns the source UnboundMethod's name (not the name given to define_method)" do
2430
klass = Class.new { define_method(:my_inspect, ::Kernel.instance_method(:inspect)) }
2531
klass.instance_method(:my_inspect).original_name.should == :inspect

0 commit comments

Comments
 (0)