Skip to content

Commit 08091ad

Browse files
committed
Add spec for missing or faulty to_proc methods
Followup: ruby#14463
1 parent ac24f70 commit 08091ad

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

spec/ruby/language/fixtures/send.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ def to_proc
8181
end
8282
end
8383

84+
class RawToProc
85+
def initialize(to_proc)
86+
@to_proc = to_proc
87+
end
88+
89+
def to_proc
90+
@to_proc
91+
end
92+
end
93+
8494
class ToAry
8595
def initialize(obj)
8696
@obj = obj

spec/ruby/language/send_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@
106106
specs.yield_now(&o).should == :from_to_proc
107107
end
108108

109+
ruby_version_is "3.5" do
110+
it "raises TypeError if 'to_proc' doesn't return a Proc" do
111+
o = LangSendSpecs::RawToProc.new(42)
112+
113+
-> {
114+
specs.makeproc(&o)
115+
}.should raise_error(TypeError, "can't convert LangSendSpecs::RawToProc to Proc (LangSendSpecs::RawToProc#to_proc gives Integer)")
116+
end
117+
118+
it "raises TypeError if block object isn't a Proc and doesn't respond to `to_proc`" do
119+
o = Object.new
120+
121+
-> {
122+
specs.makeproc(&o)
123+
}.should raise_error(TypeError, "no implicit conversion of Object into Proc")
124+
end
125+
end
126+
109127
it "raises a SyntaxError with both a literal block and an object as block" do
110128
-> {
111129
eval "specs.oneb(10, &l){ 42 }"

0 commit comments

Comments
 (0)