diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-05-28 22:41:48 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-05-28 22:41:48 +0200 |
commit | a66bc2c01194a9c017c874a30db5b3b6bd95e966 (patch) | |
tree | 598d6375b44fd86f90c3477c73086f6fcf08d76c /spec/ruby/core/proc | |
parent | d070523e7be4b95914adeef9a10401fba7718c5a (diff) |
Update to ruby/spec@9a501a8
Diffstat (limited to 'spec/ruby/core/proc')
-rw-r--r-- | spec/ruby/core/proc/new_spec.rb | 11 | ||||
-rw-r--r-- | spec/ruby/core/proc/shared/call_arguments.rb | 22 |
2 files changed, 33 insertions, 0 deletions
diff --git a/spec/ruby/core/proc/new_spec.rb b/spec/ruby/core/proc/new_spec.rb index 7579bfe1b6..60a7320e4b 100644 --- a/spec/ruby/core/proc/new_spec.rb +++ b/spec/ruby/core/proc/new_spec.rb @@ -190,6 +190,17 @@ describe "Proc.new without a block" do prc.call.should == "hello" end + + it "uses the implicit block from an enclosing method when called inside a block" do + def some_method + proc do |&block| + Proc.new + end.call { "failing" } + end + prc = some_method { "hello" } + + prc.call.should == "hello" + end end ruby_version_is "2.7" do diff --git a/spec/ruby/core/proc/shared/call_arguments.rb b/spec/ruby/core/proc/shared/call_arguments.rb index 2e510b194e..a937bd99d0 100644 --- a/spec/ruby/core/proc/shared/call_arguments.rb +++ b/spec/ruby/core/proc/shared/call_arguments.rb @@ -4,4 +4,26 @@ describe :proc_call_block_args, shared: true do lambda {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2 proc {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2 end + + it "yields to the block given at declaration and not to the block argument" do + proc_creator = Object.new + def proc_creator.create + Proc.new do |&b| + yield + end + end + a_proc = proc_creator.create { 7 } + a_proc.send(@method) { 3 }.should == 7 + end + + it "can call its block argument declared with a block argument" do + proc_creator = Object.new + def proc_creator.create(method_name) + Proc.new do |&b| + yield + b.send(method_name) + end + end + a_proc = proc_creator.create(@method) { 7 } + a_proc.call { 3 }.should == 10 + end end |