-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix keyword arguments in dynamic method dispatch #2509
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
Changes from all commits
ec244b0
e4b3953
e2541f0
cb7e2d4
0b74226
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,6 +19,13 @@ def group_for(klass) | |||||||||||
expect(group.included_modules).to include(RSpec::Rails::Matchers::RoutingMatchers) | ||||||||||||
end | ||||||||||||
|
||||||||||||
it "handles methods invoked via `method_missing` that use keywords" do | ||||||||||||
example = group.new | ||||||||||||
example.define_singleton_method(:has_val?) { |val:| val == 1 } | ||||||||||||
expect(example).to example.have_val(val: 1) | ||||||||||||
JonRowe marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
expect(example).to_not example.have_val(val: 2) | ||||||||||||
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. This test is not hitting the The current expect { example.have_val(val: 1) }.not_to raise_error failed to catch the regression, it doesn't fail if I'll figure out a self-explanatory spec to cover this. I intend to rely on dynamic matchers, but will try to avoid the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just don't want a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit of both. To reproduce the issue:
We could write a spec with something like There are dynamic matchers. They do exactly what we want - they have a It's still a brain-teaser how to express the case in a spec. The best I could think of so far: expect {
example.have_val(val: 1).matches?(example)
}.not_to raise_error
It's not necessary to call expect(example).to have_val(val: 1) but in this case 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 commentThe 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 commentThe 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, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Right. Dynamic matchers are a victim here. |
||||||||||||
end | ||||||||||||
|
||||||||||||
context "with implicit subject" do | ||||||||||||
it "uses the controller as the subject" do | ||||||||||||
controller = double('controller') | ||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.