Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds spec for an empty keyword splat to a method that does not accept… #799

Merged
merged 2 commits into from
Oct 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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