Skip to content

Commit d86c0dc

Browse files
committed
Add specs for Kernel#singlaton_method() that should support methods from included/prepended in a singleton class modules
1 parent 98bdca3 commit d86c0dc

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

core/kernel/singleton_method_spec.rb

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require_relative '../../spec_helper'
22

33
describe "Kernel#singleton_method" do
4-
it "find a method defined on the singleton class" do
4+
it "finds a method defined on the singleton class" do
55
obj = Object.new
66
def obj.foo; end
77
obj.singleton_method(:foo).should be_an_instance_of(Method)
@@ -38,4 +38,48 @@ def foo
3838
e.class.should == NameError
3939
}
4040
end
41+
42+
ruby_bug "#20620", ""..."3.4" do
43+
it "finds a method defined in a module included in the singleton class" do
44+
m = Module.new do
45+
def foo
46+
:foo
47+
end
48+
end
49+
50+
obj = Object.new
51+
obj.singleton_class.include(m)
52+
53+
obj.singleton_method(:foo).should be_an_instance_of(Method)
54+
obj.singleton_method(:foo).call.should == :foo
55+
end
56+
57+
it "finds a method defined in a module prepended in the singleton class" do
58+
m = Module.new do
59+
def foo
60+
:foo
61+
end
62+
end
63+
64+
obj = Object.new
65+
obj.singleton_class.prepend(m)
66+
67+
obj.singleton_method(:foo).should be_an_instance_of(Method)
68+
obj.singleton_method(:foo).call.should == :foo
69+
end
70+
71+
it "finds a method defined in a module that an object is extended with" do
72+
m = Module.new do
73+
def foo
74+
:foo
75+
end
76+
end
77+
78+
obj = Object.new
79+
obj.extend(m)
80+
81+
obj.singleton_method(:foo).should be_an_instance_of(Method)
82+
obj.singleton_method(:foo).call.should == :foo
83+
end
84+
end
4185
end

0 commit comments

Comments
 (0)