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 1 commit
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
28 changes: 28 additions & 0 deletions language/method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,22 @@ def m(a, b = nil, c = nil, d, e: nil, **f)
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
suppress_warning do
m(**h).should == {}
end
end.should_not raise_error
Copy link
Member

@andrykonchin andrykonchin Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for not raising exception is excessive to it's a common practice in RubySpec not to use it at all. If exception is raised a test will fail anyway.

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 +1722,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