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

Add specs to feature 14183 #878

Merged
merged 3 commits into from
Oct 15, 2021
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
52 changes: 52 additions & 0 deletions language/method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,58 @@ def m(...) = mm(...) + mm(...)
end
end
end

describe "Keyword arguments are now separated from positional arguments" do
context "with a keyword argument defined in args" do
context "when it's not used explicity" do
sergio-hilgert marked this conversation as resolved.
Show resolved Hide resolved
evaluate <<-ruby do
def foo(a, b, c, hsh)
hsh[:key]
end
ruby

foo(1, 2, 3, { key: 42 }).should raise_error(ArgumentError)
sergio-hilgert marked this conversation as resolved.
Show resolved Hide resolved
end
end

context "when it's used explicity" do
evaluate <<-ruby do
def foo(a, b, c, **hsh)
hsh[:key]
end
ruby

foo(1, 2, 3, { key: 42 }).should == 42
sergio-hilgert marked this conversation as resolved.
Show resolved Hide resolved
end
end
end

context "with a keyword argument in method call" do
context "when it's not used explicity" do
evaluate <<-ruby do
def foo(a, b, c, key: 1)
hsh[:key]
end
ruby

h = { key: 42 }
foo(1, 2, 3, h).should raise_error(ArgumentError)
end
end

context "when it's used explicity" do
evaluate <<-ruby do
def foo(a, b, c, key: 1)
hsh[:key]
end
ruby

h = { key: 42 }
foo(1, 2, 3, **h).should == 42
end
end
end
end
end

ruby_version_is "3.1" do
Expand Down