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.
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
Fix keyword arguments in dynamic method dispatch #2509
Fix keyword arguments in dynamic method dispatch #2509
Changes from all commits
ec244b0
e4b3953
e2541f0
cb7e2d4
0b74226
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
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.
I'd prefer a clear example method here not something imitating a matcher as thats not what is the issue.
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.
This test is not hitting the
method_missing
. We definedkeyword_value
and call it.The current
expect(example).to example.have_val(val: 1)
works, but it's incredibly confusing.failed to catch the regression, it doesn't fail if
ruby2_keywords
is removed.I'll figure out a self-explanatory spec to cover this. I intend to rely on dynamic matchers, but will try to avoid the
expect(example).to
part.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.
I just don't want a
have_
anything style example, its confusing, its the method dispatch thats the bug here, not matchers.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.
It's a bit of both.
To reproduce the issue:
method_missing
won't be calledmethod_missing
belowControllerExampleGroup
and below RailsWe could write a spec with something like
prepend Module.new { def method_missing ... }
, but this might be excessively complicated.There are dynamic matchers. They do exactly what we want - they have a
method_missing
, and they can delegate to the method we define.It's still a brain-teaser how to express the case in a spec. The best I could think of so far:
example.have_val
goes throughControllerExampleGroup
'smethod_missing
, then through Rails' one, and lands in dynamic matchers. They save the kwarg to@args
, and the flag that it's a kwarg is already set on the object.matches?
callshas_val?
on theexample
, and passes*@args
to it.It's not necessary to call
have_val
onexample
, and we could:but in this case
ControllerExampleGroup
'smethod_missing
is never called, and it's dynamic matchers'method_missing
who sets the flag. I.e. this fix would not be covered by such a test.Frankly speaking, it seems like it doesn't matter much what exactly the spec will be, we'll have to add a chunk of code comments along. And I have strong doubts that in a month from now it will take me less than half an hour to recall all the details about this tangled case.
I'm out of good ideas.
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.
If my change doesn't trigger method missing neither does the original, they both call the method directly I just skip the expect to. So my original point stands here, please construct an example that doesn't look like a matcher.
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.
@JonRowe There is a significant difference. You call a method that we've just defined,
keyword_value
, while the original example calls a non-existent method,have_val
, while we definehas_val?
.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.
Ah tired eyes etc, ok fine, implement a method missing and remove the has / have names. This is a lot of conversation for a simple fix, but it needs to not be confused with matchers. Its method_missing and the method names that are causing this.
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.
Right. Dynamic matchers are a victim here.
And they are the only known victim. And they apparently are the only way to test the fix without involving
in_sub_process { ControllerExampleGroup.prepend Module.new { def method_missing ... end } }
.