Skip to content

Commit

Permalink
spec: suppress deprecations of "lambda(&proc_block)" pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Dec 12, 2020
1 parent efbef72 commit 7ef5226
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
16 changes: 10 additions & 6 deletions spec/ruby/core/kernel/lambda_spec.rb
Expand Up @@ -27,8 +27,10 @@
end

it "creates a lambda-style Proc if given a literal block via Kernel.public_send" do
l = Kernel.public_send(:lambda) { 42 }
l.lambda?.should be_true
suppress_warning do
l = Kernel.public_send(:lambda) { 42 }
l.lambda?.should be_true
end
end

it "returns the passed Proc if given an existing Proc" do
Expand All @@ -39,11 +41,13 @@
end

it "creates a lambda-style Proc when called with zsuper" do
l = KernelSpecs::LambdaSpecs::ForwardBlockWithZSuper.new.lambda { 42 }
l.lambda?.should be_true
l.call.should == 42
suppress_warning do
l = KernelSpecs::LambdaSpecs::ForwardBlockWithZSuper.new.lambda { 42 }
l.lambda?.should be_true
l.call.should == 42

lambda { l.call(:extra) }.should raise_error(ArgumentError)
lambda { l.call(:extra) }.should raise_error(ArgumentError)
end
end

it "returns the passed Proc if given an existing Proc through super" do
Expand Down
4 changes: 3 additions & 1 deletion spec/ruby/core/kernel/shared/lambda.rb
Expand Up @@ -4,6 +4,8 @@
end

it "raises an ArgumentError when no block is given" do
-> { send(@method) }.should raise_error(ArgumentError)
suppress_warning do
-> { send(@method) }.should raise_error(ArgumentError)
end
end
end
12 changes: 8 additions & 4 deletions spec/ruby/language/lambda_spec.rb
Expand Up @@ -348,7 +348,9 @@ def obj.define
end

it "requires a block" do
lambda { lambda }.should raise_error(ArgumentError)
suppress_warning do
lambda { lambda }.should raise_error(ArgumentError)
end
end

it "may include a rescue clause" do
Expand All @@ -375,9 +377,11 @@ def meth; lambda; end
ruby_version_is "2.7" do
it "raises ArgumentError" do
implicit_lambda = nil
-> {
meth { 1 }
}.should raise_error(ArgumentError, /tried to create Proc object without a block/)
suppress_warning do
-> {
meth { 1 }
}.should raise_error(ArgumentError, /tried to create Proc object without a block/)
end
end
end
end
Expand Down

0 comments on commit 7ef5226

Please sign in to comment.