-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
Allow keyword arguments to match an expectation expecting *only* positional arguments #732
Merged
floehopper
merged 15 commits into
main
from
allow-keyword-arguments-to-be-used-for-method-accepting-only-postional-arguments
Jan 24, 2025
Merged
Allow keyword arguments to match an expectation expecting *only* positional arguments #732
floehopper
merged 15 commits into
main
from
allow-keyword-arguments-to-be-used-for-method-accepting-only-postional-arguments
Jan 24, 2025
Conversation
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
To `expected_value` to make the code clearer.
To `actual_values` to make the code clearer.
To `actual_value` and `is_last_parameter` to `is_last_actual_value` and `#extract_parameter` to `#extract_actual_value` to make the code clearer.
The test passing is more important than whether there was a deprecation warning. Also it means we can use a guard condition and thus avoid the indentation in the `if` condition branch which I think makes the tests more readable.
Previously, *all* of the tests in `StrictPositionalOrKeywordHashTest` had a `if Mocha::RUBY_V27_PLUS` condition around them. Now the whole test case has that condition which means we can simplify the `#setup` and `#teardown` methods. c.f. this commit [1]. [1]: 097446d
To make `#matches?` more readable.
To make the logic a bit more readable.
To make the logic a bit more readable.
To make `#matches_last_actual_value?` more readable.
To make the logic a bit more readable.
To make `#matches?` a bit more readable.
floehopper
force-pushed
the
allow-keyword-arguments-to-be-used-for-method-accepting-only-postional-arguments
branch
from
January 24, 2025 12:06
85d75a3
to
ca39d5b
Compare
I think it's worth violating the cop in this case in order to make the logic clearer / more explicit.
floehopper
deleted the
allow-keyword-arguments-to-be-used-for-method-accepting-only-postional-arguments
branch
January 24, 2025 14:24
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TODO:
PositionalOrKeywordHash#matches?
[ ] Maybe use keyword arguments forPositionalOrKeywordHash
constructorThis is a (very belated) possible fix for #593.
According to these docs:
This solution takes an alternative approach to #605 which depended on #532. Instead of basing the logic in
Mocha::ParameterMatchers::PositionalOrKeywordHash#matches?
on the original method signature, it bases it on the expected arguments, i.e. the parameter matchers. Since keyword arguments can only appear after all positional arguments, we can detect an expectation which only expects positional arguments by checking whether the last parameter matcher is expecting a positional Hash or a keyword Hash. If it's expecting a positional Hash then we can assume the expectation only expects positional arguments and thus it should successfully match keyword arguments with that positional Hash without issuing a deprecation warning.I think my work on #532 at the time must've blinded me to the idea that we needed to base the logic on the original method signature which is a considerably more complicated undertaking. Although the solution in this PR might not be perfect, I think it's probably an improvement and we can look at ensuring that expected parameters match the original method signature as a separate issue which relates to #149, #531 & #532.
Before fix
After fix