diff options
Diffstat (limited to 'spec/ruby/core')
| -rw-r--r-- | spec/ruby/core/kernel/proc_spec.rb | 24 | ||||
| -rw-r--r-- | spec/ruby/core/proc/block_pass_spec.rb | 45 | ||||
| -rw-r--r-- | spec/ruby/core/proc/new_spec.rb | 53 |
3 files changed, 89 insertions, 33 deletions
diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb index d9c09117e7..2c0e7988f9 100644 --- a/spec/ruby/core/kernel/proc_spec.rb +++ b/spec/ruby/core/kernel/proc_spec.rb @@ -36,14 +36,28 @@ describe "Kernel.proc" do end describe "Kernel#proc" do - it "uses the implicit block from an enclosing method" do - def some_method - proc + ruby_version_is ""..."2.7" do + it "uses the implicit block from an enclosing method" do + def some_method + proc + end + + prc = some_method { "hello" } + + prc.call.should == "hello" end + end - prc = some_method { "hello" } + ruby_version_is "2.7" do + it "can be created when called with no block" do + def some_method + proc + end - prc.call.should == "hello" + -> { + some_method { "hello" } + }.should complain(/tried to create Proc object without a block/) + end end it "needs to be reviewed for spec completeness" diff --git a/spec/ruby/core/proc/block_pass_spec.rb b/spec/ruby/core/proc/block_pass_spec.rb index 282f00b5a8..917a38efac 100644 --- a/spec/ruby/core/proc/block_pass_spec.rb +++ b/spec/ruby/core/proc/block_pass_spec.rb @@ -20,22 +20,39 @@ describe "Proc as a block pass argument" do end end -describe "Proc as an implicit block pass argument" do - def revivify - Proc.new - end +ruby_version_is ""..."2.7" do + describe "Proc as an implicit block pass argument" do + def revivify + Proc.new + end - it "remains the same object if re-vivified by the target method" do - p = Proc.new {} - p2 = revivify(&p) - p.should equal p2 - p.should == p2 + it "remains the same object if re-vivified by the target method" do + p = Proc.new {} + p2 = revivify(&p) + p.should equal p2 + p.should == p2 + end + + it "remains the same object if reconstructed with Proc.new" do + p = Proc.new {} + p2 = Proc.new(&p) + p.should equal p2 + p.should == p2 + end end +end - it "remains the same object if reconstructed with Proc.new" do - p = Proc.new {} - p2 = Proc.new(&p) - p.should equal p2 - p.should == p2 +ruby_version_is "2.7" do + describe "Proc called with no block" do + def revivify + Proc.new + end + + it "raises ArgumentError when called with no block" do + p = Proc.new {} + -> { + revivify(&p) + }.should + end end end diff --git a/spec/ruby/core/proc/new_spec.rb b/spec/ruby/core/proc/new_spec.rb index abdd187276..1c37c64478 100644 --- a/spec/ruby/core/proc/new_spec.rb +++ b/spec/ruby/core/proc/new_spec.rb @@ -95,16 +95,18 @@ describe "Proc.new with an associated block" do obj.second.should == 2 end - it "returns a new Proc instance from the block passed to the containing method" do - prc = ProcSpecs.new_proc_in_method { "hello" } - prc.should be_an_instance_of(Proc) - prc.call.should == "hello" - end + ruby_version_is ""..."2.7" do + it "returns a new Proc instance from the block passed to the containing method" do + prc = ProcSpecs.new_proc_in_method { "hello" } + prc.should be_an_instance_of(Proc) + prc.call.should == "hello" + end - it "returns a new Proc instance from the block passed to the containing method" do - prc = ProcSpecs.new_proc_subclass_in_method { "hello" } - prc.should be_an_instance_of(ProcSpecs::ProcSubclass) - prc.call.should == "hello" + it "returns a new Proc instance from the block passed to the containing method" do + prc = ProcSpecs.new_proc_subclass_in_method { "hello" } + prc.should be_an_instance_of(ProcSpecs::ProcSubclass) + prc.call.should == "hello" + end end end @@ -178,13 +180,36 @@ describe "Proc.new without a block" do lambda { ProcSpecs.new_proc_subclass_in_method }.should raise_error(ArgumentError) end - it "uses the implicit block from an enclosing method" do - def some_method - Proc.new + ruby_version_is ""..."2.7" do + it "uses the implicit block from an enclosing method" do + def some_method + Proc.new + end + + prc = some_method { "hello" } + + prc.call.should == "hello" + end + end + + ruby_version_is "2.7" do + it "can be created if invoked from within a method with a block" do + lambda { ProcSpecs.new_proc_in_method { "hello" } }.should complain(/tried to create Proc object without a block/) + end + + it "can be created if invoked on a subclass from within a method with a block" do + lambda { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should complain(/tried to create Proc object without a block/) end - prc = some_method { "hello" } - prc.call.should == "hello" + it "can be create when called with no block" do + def some_method + Proc.new + end + + -> { + some_method { "hello" } + }.should complain(/tried to create Proc object without a block/) + end end end |
