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.rb98
1 files changed, 32 insertions, 66 deletions
diff --git a/spec/ruby/language/lambda_spec.rb b/spec/ruby/language/lambda_spec.rb
index 3b06a0d595..ed5a1c69e8 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
@@ -186,19 +184,9 @@ describe "A lambda literal -> () { }" do
@a.().should == {}
@a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- def self.suppress_keyword_warning(&block)
- if RUBY_VERSION > '2.7'
- suppress_warning(&block)
- else
- yield
- end
- end
-
- suppress_keyword_warning do
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- @a.(h).should == {a: 1}
- end
+ h = mock("keyword splat")
+ h.should_not_receive(:to_hash)
+ @a.(h).should == {}
end
evaluate <<-ruby do
@@ -275,20 +263,21 @@ describe "A lambda literal -> () { }" do
end
describe "with circular optional argument reference" do
- it "shadows an existing local with the same name as the argument" do
- a = 1
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
+ ruby_version_is ""..."3.4" do
+ it "raises a SyntaxError if using the argument in its default value" do
+ a = 1
+ -> {
+ eval "-> (a=a) { a }"
+ }.should raise_error(SyntaxError)
+ end
end
- it "shadows an existing method with the same name as the argument" do
- def a; 1; end
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
+ ruby_version_is "3.4" do
+ it "is nil if using the argument in its default value" do
+ -> {
+ eval "-> (a=a) { a }.call"
+ }.call.should == nil
+ end
end
it "calls an existing method with the same name as the argument if explicitly using ()" do
@@ -322,36 +311,23 @@ 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
def meth; lambda; end
end
- ruby_version_is ""..."2.7" do
- it "can be created" do
- implicit_lambda = nil
- -> {
- implicit_lambda = meth { 1 }
- }.should complain(/tried to create Proc object without a block/)
-
- implicit_lambda.lambda?.should be_true
- implicit_lambda.call.should == 1
- end
- end
-
- ruby_version_is "2.7" do
- it "raises ArgumentError" do
- implicit_lambda = nil
+ it "raises ArgumentError" do
+ implicit_lambda = nil
+ suppress_warning do
-> {
meth { 1 }
}.should raise_error(ArgumentError, /tried to create Proc object without a block/)
@@ -530,19 +506,9 @@ describe "A lambda expression 'lambda { ... }'" do
@a.().should == {}
@a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- def self.suppress_keyword_warning(&block)
- if RUBY_VERSION > '2.7'
- suppress_warning(&block)
- else
- yield
- end
- end
-
- suppress_keyword_warning do
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- @a.(h).should == {a: 1}
- end
+ h = mock("keyword splat")
+ h.should_not_receive(:to_hash)
+ @a.(h).should == {}
end
evaluate <<-ruby do