-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
! Fix keyword arguments contract when used with optional positional a…
…rguments
- Loading branch information
1 parent
8be37e8
commit b0eccc3
Showing
3 changed files
with
70 additions
and
27 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
features/builtin_contracts/keyword_args_with_optional_positional_args.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Feature: KeywordArgs when used with optional positional arguments | ||
|
||
Checks that the argument is an options hash, and all required keyword arguments are present, and all values pass their respective contracts | ||
|
||
```ruby | ||
Contract Any, KeywordArgs[:number => Num, :description => Optional[String]] => Any | ||
``` | ||
|
||
Background: | ||
Given a file named "keyword_args_with_optional_positional_args_usage.rb" with: | ||
"""ruby | ||
require "contracts" | ||
C = Contracts | ||
class Example | ||
include Contracts::Core | ||
Contract C::Any, String, C::KeywordArgs[b: C::Optional[String]] => Symbol | ||
def foo(output, a = 'a', b: 'b') | ||
p [a, b] | ||
output | ||
end | ||
end | ||
""" | ||
|
||
Scenario: Accepts arguments when only require arguments filled and valid | ||
Given a file named "accepts_all_filled_valid_args.rb" with: | ||
"""ruby | ||
require "./keyword_args_with_optional_positional_args_usage" | ||
puts Example.new.foo(:output) | ||
""" | ||
When I run `ruby accepts_all_filled_valid_args.rb` | ||
Then output should contain: | ||
""" | ||
["a", "b"] | ||
output | ||
""" | ||
|
||
Scenario: Accepts arguments when all filled and valid | ||
Given a file named "accepts_all_filled_valid_args.rb" with: | ||
"""ruby | ||
require "./keyword_args_with_optional_positional_args_usage" | ||
puts Example.new.foo(:output, 'c', b: 'd') | ||
""" | ||
When I run `ruby accepts_all_filled_valid_args.rb` | ||
Then output should contain: | ||
""" | ||
["c", "d"] | ||
output | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters