Skip to content

Commit c2538ad

Browse files
authored
Merge pull request #35 from varun-iyer/master
Add a koan for mandatory keyword arguments
2 parents 3334d7d + c7a56e5 commit c2538ad

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/about_keyword_arguments.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,20 @@ def test_keyword_arguments_with_wrong_number_of_arguments
2424
assert_match(/#{__("wrong number of arguments")}/, exception.message)
2525
end
2626

27-
# THINK ABOUT IT:
28-
#
29-
# Keyword arguments always have a default value, making them optional to the caller
27+
def method_with_mandatory_keyword_arguments(one:, two: 'two')
28+
[one, two]
29+
end
30+
31+
def test_mandatory_keyword_arguments
32+
assert_equal __(['one', 'two']), method_with_mandatory_keyword_arguments(one: 'one')
33+
assert_equal __([1, 2]), method_with_mandatory_keyword_arguments(two: 2, one: 1)
34+
end
35+
36+
def test_mandatory_keyword_arguments_without_mandatory_argument
37+
exception = assert_raise(___(ArgumentError)) do
38+
method_with_mandatory_keyword_arguments
39+
end
40+
assert_match(/#{__("missing keyword: :one")}/, exception.message)
41+
end
3042

3143
end

0 commit comments

Comments
 (0)