summaryrefslogtreecommitdiff
path: root/spec/ruby/core/proc/new_spec.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-10 08:19:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-10 08:19:14 +0000
commit9f1fb0a17febc59356d58cef5e98db61a3c03550 (patch)
tree14c3bf6cd585b859d030ec8d41e6b6e16b0e01e7 /spec/ruby/core/proc/new_spec.rb
parentec336fb40e4df0c8615e584fbefb5e9e572cb9ec (diff)
proc.c: proc without block
* proc.c (proc_new): promoted lambda/proc/Proc.new with no block in a method called with a block to a warning/error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/proc/new_spec.rb')
-rw-r--r--spec/ruby/core/proc/new_spec.rb53
1 files changed, 39 insertions, 14 deletions
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