Allow keyword arguments to match an expectation expecting *only* positional arguments #732
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:
This 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