Skip to content

Commit 6dca58c

Browse files
committed
Add more specs for Method and UnboundMethod#inspect
1 parent f65ce6f commit 6dca58c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

spec/ruby/core/method/shared/to_s.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
describe :method_to_s, shared: true do
55
before :each do
66
@m = MethodSpecs::MySub.new.method :bar
7-
@string = @m.send(@method).sub(/0x\w+/, '0xXXXXXX')
7+
@string = @m.send(@method)
88
end
99

1010
it "returns a String" do
@@ -32,21 +32,29 @@
3232
@string.should =~ /MethodSpecs::MySub/
3333
end
3434

35+
it "returns a String including all details" do
36+
@string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
37+
end
38+
39+
it "does not show the defining module if it is the same as the receiver class" do
40+
MethodSpecs::A.new.method(:baz).send(@method).should.start_with? "#<Method: MethodSpecs::A#baz"
41+
end
42+
3543
ruby_version_is '3.0' do
3644
it "returns a String containing the Module containing the method if object has a singleton class but method is not defined in the singleton class" do
3745
obj = MethodSpecs::MySub.new
3846
obj.singleton_class
3947
@m = obj.method(:bar)
40-
@string = @m.send(@method).sub(/0x\w+/, '0xXXXXXX')
41-
@string.should =~ /\A#<Method: MethodSpecs::MySub\(MethodSpecs::MyMod\)#bar\(\) /
48+
@string = @m.send(@method)
49+
@string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
4250
end
4351
end
4452

4553
it "returns a String containing the singleton class if method is defined in the singleton class" do
4654
obj = MethodSpecs::MySub.new
4755
def obj.bar; end
4856
@m = obj.method(:bar)
49-
@string = @m.send(@method).sub(/0x\w+/, '0xXXXXXX')
50-
@string.should =~ /\A#<Method: #<MethodSpecs::MySub:0xXXXXXX>\.bar/
57+
@string = @m.send(@method).sub(/0x\h+/, '0xXXXXXX')
58+
@string.should.start_with? "#<Method: #<MethodSpecs::MySub:0xXXXXXX>.bar"
5159
end
5260
end

spec/ruby/core/unboundmethod/shared/to_s.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,13 @@
2222
@from_module.send(@method).should =~ /\bUnboundMethodSpecs::Mod\b/
2323
@from_method.send(@method).should =~ /\bUnboundMethodSpecs::Methods\b/
2424
end
25+
26+
it "returns a String including all details" do
27+
@from_module.send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Methods(UnboundMethodSpecs::Mod)#from_mod"
28+
@from_method.send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Methods(UnboundMethodSpecs::Mod)#from_mod"
29+
end
30+
31+
it "does not show the defining module if it is the same as the origin" do
32+
UnboundMethodSpecs::A.instance_method(:baz).send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::A#baz"
33+
end
2534
end

0 commit comments

Comments
 (0)