diff --git a/language/method_spec.rb b/language/method_spec.rb index f2e85ee05e..960c8dfba3 100644 --- a/language/method_spec.rb +++ b/language/method_spec.rb @@ -1688,6 +1688,32 @@ def m(a, b = nil, c = nil, d, e: nil, **f) end end + ruby_version_is '2.7' do + context 'when passing an empty keyword splat to a method that does not accept keywords' do + evaluate <<-ruby do + def m(*a); a; end + ruby + + h = {} + m(**h).should == [] + end + end + end + + ruby_version_is '2.7'...'3.0' do + context 'when passing an empty keyword splat to a method that does not accept keywords' do + evaluate <<-ruby do + def m(a); a; end + ruby + h = {} + + -> do + m(**h).should == {} + end.should complain(/warning: Passing the keyword argument as the last hash parameter is deprecated/) + end + end + end + ruby_version_is ''...'3.0' do context "assigns keyword arguments from a passed Hash without modifying it" do evaluate <<-ruby do @@ -1706,6 +1732,18 @@ def m(a: nil); a; end end ruby_version_is '3.0' do + context 'when passing an empty keyword splat to a method that does not accept keywords' do + evaluate <<-ruby do + def m(a); a; end + ruby + h = {} + + -> do + m(**h).should == {} + end.should raise_error(ArgumentError) + end + end + context "raises ArgumentError if passing hash as keyword arguments" do evaluate <<-ruby do def m(a: nil); a; end