Skip to content

Commit

Permalink
Merge pull request #35 from varun-iyer/master
Browse files Browse the repository at this point in the history
Add a koan for mandatory keyword arguments
  • Loading branch information
tonywok authored Aug 9, 2023
2 parents 3334d7d + c7a56e5 commit c2538ad
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/about_keyword_arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@ def test_keyword_arguments_with_wrong_number_of_arguments
assert_match(/#{__("wrong number of arguments")}/, exception.message)
end

# THINK ABOUT IT:
#
# Keyword arguments always have a default value, making them optional to the caller
def method_with_mandatory_keyword_arguments(one:, two: 'two')
[one, two]
end

def test_mandatory_keyword_arguments
assert_equal __(['one', 'two']), method_with_mandatory_keyword_arguments(one: 'one')
assert_equal __([1, 2]), method_with_mandatory_keyword_arguments(two: 2, one: 1)
end

def test_mandatory_keyword_arguments_without_mandatory_argument
exception = assert_raise(___(ArgumentError)) do
method_with_mandatory_keyword_arguments
end
assert_match(/#{__("missing keyword: :one")}/, exception.message)
end

end

0 comments on commit c2538ad

Please sign in to comment.