-
-
Notifications
You must be signed in to change notification settings - Fork 103
[bugfix] Properly detect kwargs hashes vs optional positional args #594
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
0645cdf
to
2b4d422
Compare
2b4d422
to
ef33ab7
Compare
d61bf73
to
c0ea86c
Compare
990054f
to
6eb38eb
Compare
75432d1
to
fd1dbb6
Compare
Fully backwards compatible, just need to fix 3.2 and up. The behavior of ruby2_keywords changed between 3.1 and 3.2: https://rubyreferences.github.io/rubychanges/3.2.html#keyword-argument-separation-leftovers |
def initialize(signature, args=[]) | ||
@signature = signature | ||
@non_kw_args, @kw_args = split_args(*args) | ||
@non_kw_args, @kw_args = split_args(args.clone) | ||
@min_non_kw_args = @max_non_kw_args = @non_kw_args | ||
@arbitrary_kw_args = @unlimited_args = false | ||
end |
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.
something had to change here. Splatting the args meant the special marking for the kwargs hash gets lost. This doesnt happen to functions with the ruby2_keywords... except it won't apply here because this function doesn't take the *args input. So either the args array is cloned (which persists the special flagging) or the input to this function needs to swap to using *args. I figured cloning was the less obtrusive change. The split_args function is private so changing its signature was not something that has compatibility concerns.
Apologies I never got round to looking at this, I've migrated it over to the monorepo as rspec/rspec#121 I'm hoping to do a big refactoring of keyword argument support with RSpec 4 dropping older ruby support. |
Attempting to fix https://github.com/rspec/rspec-expectations/issues/1451
Refactor
has_kw_args_in?
:Added backwards compatible ruby2_keywords wrapping to the necessary methods (valid? and error_for) in the spec files like so:
ruby2_keywords(:valid?) if respond_to?(:ruby2_keywords, true)
Also needed to modify how args are passed to the MSV split_args so that the special kwargs markings are not lost.