summaryrefslogtreecommitdiff
path: root/spec/ruby/language/proc_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/language/proc_spec.rb')
-rw-r--r--spec/ruby/language/proc_spec.rb35
1 files changed, 19 insertions, 16 deletions
diff --git a/spec/ruby/language/proc_spec.rb b/spec/ruby/language/proc_spec.rb
index ef4a43bed6..cc69b7799c 100644
--- a/spec/ruby/language/proc_spec.rb
+++ b/spec/ruby/language/proc_spec.rb
@@ -161,6 +161,18 @@ describe "A Proc" do
end
end
+ describe "taking |*a, b| arguments" do
+ it "assigns [] to the argument when passed no values" do
+ proc { |*a, b| [a, b] }.call.should == [[], nil]
+ end
+ end
+
+ describe "taking |a, *b, c| arguments" do
+ it "assigns [] to the argument when passed no values" do
+ proc { |a, *b, c| [a, b, c] }.call.should == [nil, [], nil]
+ end
+ end
+
describe "taking |a, | arguments" do
before :each do
@l = lambda { |a, | a }
@@ -223,24 +235,15 @@ describe "A Proc" do
@p = proc { |*a, **kw| [a, kw] }
end
- ruby_version_is ""..."2.7" do
- it 'autosplats keyword arguments' do
- @p.call([1, {a: 1}]).should == [[1], {a: 1}]
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
- it 'autosplats keyword arguments and warns' do
- -> {
- @p.call([1, {a: 1}]).should == [[1], {a: 1}]
- }.should complain(/warning: Using the last argument as keyword parameters is deprecated; maybe \*\* should be added to the call/)
- end
+ it 'does not autosplat keyword arguments' do
+ @p.call([1, {a: 1}]).should == [[[1, {a: 1}]], {}]
end
+ end
- ruby_version_is "3.0" do
- it 'does not autosplat keyword arguments' do
- @p.call([1, {a: 1}]).should == [[[1, {a: 1}]], {}]
- end
+ describe "taking |required keyword arguments, **kw| arguments" do
+ it "raises ArgumentError for missing required argument" do
+ p = proc { |a:, **kw| [a, kw] }
+ -> { p.call() }.should raise_error(ArgumentError)
end
end
end