summaryrefslogtreecommitdiff
path: root/spec/ruby/language/lambda_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/language/lambda_spec.rb')
-rw-r--r--spec/ruby/language/lambda_spec.rb95
1 files changed, 63 insertions, 32 deletions
diff --git a/spec/ruby/language/lambda_spec.rb b/spec/ruby/language/lambda_spec.rb
index ddd0b574b3..6393fb5c47 100644
--- a/spec/ruby/language/lambda_spec.rb
+++ b/spec/ruby/language/lambda_spec.rb
@@ -22,14 +22,12 @@ describe "A lambda literal -> () { }" do
-> { }.lambda?.should be_true
end
- ruby_version_is "2.6" do
- it "may include a rescue clause" do
- eval('-> do raise ArgumentError; rescue ArgumentError; 7; end').should be_an_instance_of(Proc)
- end
+ it "may include a rescue clause" do
+ eval('-> do raise ArgumentError; rescue ArgumentError; 7; end').should be_an_instance_of(Proc)
+ end
- it "may include a ensure clause" do
- eval('-> do 1; ensure; 2; end').should be_an_instance_of(Proc)
- end
+ it "may include a ensure clause" do
+ eval('-> do 1; ensure; 2; end').should be_an_instance_of(Proc)
end
it "has its own scope for local variables" do
@@ -179,17 +177,33 @@ describe "A lambda literal -> () { }" do
result.should == [1, 2, 3, [4, 5], 6, [7, 8], 9, 10, 11, 12]
end
- evaluate <<-ruby do
- @a = -> (*, **k) { k }
- ruby
+ ruby_version_is ''...'3.0' do
+ evaluate <<-ruby do
+ @a = -> (*, **k) { k }
+ ruby
- @a.().should == {}
- @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
+ @a.().should == {}
+ @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
+
+ suppress_keyword_warning do
+ h = mock("keyword splat")
+ h.should_receive(:to_hash).and_return({a: 1})
+ @a.(h).should == {a: 1}
+ end
+ end
+ end
+
+ ruby_version_is '3.0' do
+ evaluate <<-ruby do
+ @a = -> (*, **k) { k }
+ ruby
+
+ @a.().should == {}
+ @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- suppress_keyword_warning do
h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- @a.(h).should == {a: 1}
+ h.should_not_receive(:to_hash)
+ @a.(h).should == {}
end
end
@@ -332,15 +346,14 @@ describe "A lambda expression 'lambda { ... }'" do
end
it "requires a block" do
- lambda { lambda }.should raise_error(ArgumentError)
- end
-
- ruby_version_is "2.5" do
- it "may include a rescue clause" do
- eval('lambda do raise ArgumentError; rescue ArgumentError; 7; end').should be_an_instance_of(Proc)
+ suppress_warning do
+ lambda { lambda }.should raise_error(ArgumentError)
end
end
+ it "may include a rescue clause" do
+ eval('lambda do raise ArgumentError; rescue ArgumentError; 7; end').should be_an_instance_of(Proc)
+ end
context "with an implicit block" do
before do
@@ -362,9 +375,11 @@ describe "A lambda expression 'lambda { ... }'" do
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
@@ -533,17 +548,33 @@ describe "A lambda expression 'lambda { ... }'" do
result.should == [1, 2, 3, [4, 5], 6, [7, 8], 9, 10, 11, 12]
end
- evaluate <<-ruby do
- @a = lambda { |*, **k| k }
- ruby
+ ruby_version_is ''...'3.0' do
+ evaluate <<-ruby do
+ @a = lambda { |*, **k| k }
+ ruby
- @a.().should == {}
- @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
+ @a.().should == {}
+ @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
+
+ suppress_keyword_warning do
+ h = mock("keyword splat")
+ h.should_receive(:to_hash).and_return({a: 1})
+ @a.(h).should == {a: 1}
+ end
+ end
+ end
+
+ ruby_version_is '3.0' do
+ evaluate <<-ruby do
+ @a = lambda { |*, **k| k }
+ ruby
+
+ @a.().should == {}
+ @a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- suppress_keyword_warning do
h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- @a.(h).should == {a: 1}
+ h.should_not_receive(:to_hash)
+ @a.(h).should == {}
end
end