diff options
| author | Jean Boussier <jean.boussier@gmail.com> | 2025-09-08 11:02:54 +0200 |
|---|---|---|
| committer | Jean Boussier <jean.boussier@gmail.com> | 2025-09-08 16:22:50 +0200 |
| commit | 08091adec3f5d454efc31969a5eaf0102acea8a8 (patch) | |
| tree | e61935f1d376b03d956e427f0eddfd6cf9f79a63 | |
| parent | ac24f70fb0c0cc80d30ec6e96b3369079775d0dc (diff) | |
Add spec for missing or faulty `to_proc` methods
Followup: https://github.com/ruby/ruby/pull/14463
| -rw-r--r-- | spec/ruby/language/fixtures/send.rb | 10 | ||||
| -rw-r--r-- | spec/ruby/language/send_spec.rb | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/spec/ruby/language/fixtures/send.rb b/spec/ruby/language/fixtures/send.rb index 5d1d9da214..4787abee5c 100644 --- a/spec/ruby/language/fixtures/send.rb +++ b/spec/ruby/language/fixtures/send.rb @@ -81,6 +81,16 @@ module LangSendSpecs end end + class RawToProc + def initialize(to_proc) + @to_proc = to_proc + end + + def to_proc + @to_proc + end + end + class ToAry def initialize(obj) @obj = obj diff --git a/spec/ruby/language/send_spec.rb b/spec/ruby/language/send_spec.rb index aaccdf0998..bd69593d76 100644 --- a/spec/ruby/language/send_spec.rb +++ b/spec/ruby/language/send_spec.rb @@ -106,6 +106,24 @@ describe "Invoking a method" do specs.yield_now(&o).should == :from_to_proc end + ruby_version_is "3.5" do + it "raises TypeError if 'to_proc' doesn't return a Proc" do + o = LangSendSpecs::RawToProc.new(42) + + -> { + specs.makeproc(&o) + }.should raise_error(TypeError, "can't convert LangSendSpecs::RawToProc to Proc (LangSendSpecs::RawToProc#to_proc gives Integer)") + end + + it "raises TypeError if block object isn't a Proc and doesn't respond to `to_proc`" do + o = Object.new + + -> { + specs.makeproc(&o) + }.should raise_error(TypeError, "no implicit conversion of Object into Proc") + end + end + it "raises a SyntaxError with both a literal block and an object as block" do -> { eval "specs.oneb(10, &l){ 42 }" |
