-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Show proof of concept for keyword arg matching #534
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
94c6525
Show proof of concept for keyword arg matching
wasabigeek 73c98e4
Fix handling of last positional args
wasabigeek 7b823bc
WIP: Fix StubbaExampleTest
floehopper f3ba1d6
WIP: Fix support for older versions of Ruby
floehopper d6da11e
WIP: Fix rubocop issues
floehopper 2da7951
WIP: Fix Yardoc for LastPositionalHash
floehopper 4667ce6
WIP: Centralize check for keyword argument support
floehopper 2b1067b
Handle last positional arg in with statement
wasabigeek c1d3b2c
Revert stubba_example_test changes
wasabigeek 96e71ad
Add more ruby2_keywords
wasabigeek cf19d36
Attempt to polymorphise to_matchers
wasabigeek a89cf15
Attempt to set last argument on the object itself
wasabigeek 41e9cc7
Revert "Attempt to set last argument on the object itself"
wasabigeek 44e7d41
Revert "Attempt to polymorphise to_matchers"
wasabigeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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,26 @@ | ||
require 'mocha/parameter_matchers/base' | ||
require 'mocha/ruby_version' | ||
|
||
module Mocha | ||
module ParameterMatchers | ||
# @private | ||
class LastPositionalHash < Base | ||
def initialize(value) | ||
@value = value | ||
end | ||
|
||
def matches?(available_parameters) | ||
parameter = available_parameters.shift | ||
if RUBY_V3_PLUS | ||
return false unless Hash.ruby2_keywords_hash?(@value) == Hash.ruby2_keywords_hash?(parameter) | ||
end | ||
|
||
parameter == @value | ||
end | ||
|
||
def mocha_inspect | ||
@value.mocha_inspect | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module Mocha | ||
RUBY_V2_PLUS = Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2') | ||
RUBY_V3_PLUS = Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('3') | ||
end |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, since
expected_parameters
can be matchers as well, would that break matchers for keyword arguments? e.g. thehas_value
matcherI'll check a test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current implementation it still works, this passes:
However, I think it's because the keyword arg check only happens if the last expected param is a Hash, which in this case it isn't:
mocha/lib/mocha/parameters_matcher.rb
Line 32 in 44e7d41
This might become problem when we want to refactor parameters in the future (see comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To discuss further in #534 (comment)