-
-
Notifications
You must be signed in to change notification settings - Fork 910
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
with_arguments
adds non-documented arguments to delegate method call
#1382
Comments
Hey @Burgestrand, thanks for raising this issue. I think the intent here to be able to test that if you have a situation where you are manually delegating to another object, if arguments are passed to the delegating method, they get successfully passed on to the target method. So I think the documentation is incorrect. As for the tests, I checked the history and they are very old. So it's very possible that they're poorly written and that the fact that they don't represent reality very well has never been noticed. But my feeling is that in order to reflect the intent, Courier#deliver_package should take an |
Hi, @Burgestrand, I'm sorry to hear that. Can you give me more details about the problem, please? I'll take a look later.
Thanks! EDIT: You can test on master now! 😄 |
I don't have a strong opinion. I can see both being useful, but given this issue hasn't been raised before that's an argument against it 😄 When I came across this I was trying to use it as documented. Here's roughly what I intended to test: def ignored?
repository.ignored?(order_id: @id)
end I expected it to be testable as such: should delegate_method(:ignored?).to(:repository).with_arguments(order_id: "5") |
@vsppedro I tried master now, fresh install of Ruby 2.7.2 with asdf.
|
So, we need to update some dependencies so that it doesn't happen again! 😄 Thanks! |
Happy to help 😊 |
Sorry about raising an issue without a PR, I had
bin/setup
issues with Puma/bundler.The attached code, more or less copied from the documentation does not run successfully. It fails with an error. Code example at the bottom of this issue.
It's not clear to me if the documentation is wrong, or if the documentation is intended to work as it is written.
Implementation details
The reason is that the delegated arguments are not only used in the matcher, they're also added to the delegated method call (see line
423
):shoulda-matchers/lib/shoulda/matchers/independent/delegate_method_matcher.rb
Lines 419 to 425 in 64376a0
The test suite doesn't catch this because the method under test has its' arguments defined as
*
(line267
):shoulda-matchers/spec/unit/shoulda/matchers/independent/delegate_method_matcher_spec.rb
Lines 266 to 274 in 64376a0
I tried to dig a bit in the git history to figure out why it accepts any arguments, but I didn't find anything conclusive.
Reproducible code
Save to a file, run it using Ruby, e.g.
ruby example.rb
.Click here for error output
The text was updated successfully, but these errors were encountered: