-
-
Notifications
You must be signed in to change notification settings - Fork 395
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
Regression in 3.13: custom matcher hash argument improperly converted to keyword args, results in ArgumentError
#1451
Comments
Myron, thanks for reporting! Most definitely caused by rspec/rspec-support#591 |
If you change your input hash to include a Symbol key, this will fail on older versions of rspec as well I think the core of this is a bug somewhere in here:
This method signature types are [optional, key]. Obviously the code is incorrectly interpreting the optional hash as a splat arg. I think the |
I've got a draft PR of the fix up, have a few tests to touch up and reason through. Its a bit tricky because of the ambiguity of how the args get presented. You can see through the little demo the args are presented the same way whether its a straight kwargs or a hash, but the assignment of the args to parameters is different.
|
I've opened an issue in the rspec-support project. I attempted to fix this issue today, but ended up being stymied by a larger issue, namely that the argument forwarding to the code checking the methods is not ruby 3 kwargs behavior compatible. I assume the mitigation / fix for this regression will be discussed there. |
A couple updates here:
RSpec::Matchers.define :match_against_with_optional_kwarg do |hash, optional_kwarg: true|
match { |actual| true }
end ...do this: RSpec::Matchers.define :match_against_with_optional_kwarg do |hash, options = {}|
optional_kwarg = options.fetch(:optional_kwarg, true)
match { |actual| true }
end |
Subject of the issue
My project has a custom matcher defined with an optional keyword arg. After upgrading to RSpec 3.13, I get an
ArgumentError
that indicates that RSpec is converting a hash argument into keyword args for some reason.Your environment
Steps to reproduce
Create a file named
rspec_bug.rb
with these contents:Expected behavior
I expect this spec to pass, as it does on every recent version of RSpec:
Actual behavior
On RSpec 3.13, it fails with a very odd error:
The error (
ArgumentError: unknown keywords: 5, "some", "of", [:foo]
) indicates that RSpec is somehow converting my hash of data into keyword args, even though the keys aren't valid for keyword args, and it's just a hash of data being passed as a positional arg.This bug appears to be triggered by the presence of an optional keyword arg on the definition of the matcher itself.
The text was updated successfully, but these errors were encountered: