Skip to content

Commit

Permalink
Merge pull request #799 from moofkit/empty_keyword_splat
Browse files Browse the repository at this point in the history
adds spec for an empty keyword splat to a method that does not accept…
  • Loading branch information
andrykonchin authored Oct 15, 2020
2 parents 77041a3 + 8f05885 commit 4318316
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions language/method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4318316

Please sign in to comment.