From b2d8310b16bffa26f2ec4ab6c215eb92f731f063 Mon Sep 17 00:00:00 2001 From: HeroProtagonist Date: Sun, 17 Oct 2021 12:23:15 -0400 Subject: [PATCH] Add specs for proc `taking |*a, **kw| arguments` --- language/proc_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/language/proc_spec.rb b/language/proc_spec.rb index c44e711d2b..bae2a856c4 100644 --- a/language/proc_spec.rb +++ b/language/proc_spec.rb @@ -217,4 +217,30 @@ lambda { @l.call(obj) }.should raise_error(TypeError) end end + + describe "taking |*a, **kw| arguments" do + before :each 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 + end + + ruby_version_is "3.0" do + it 'does not autosplat keyword' do + @p.call([1, {a: 1}]).should == [[[1, {a: 1}]], {}] + end + end + end end