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
Delegate to private methods #531
Conversation
post_office = PostOffice.new | ||
message = 'Expected PostOffice#deliver_mail not to delegate to PostOffice#mailman, but it did' | ||
|
||
expect { |
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.
Avoid using {...} for multi-line blocks.
Sweet, thank you. I'll take a closer look at this when I get a chance. |
It was fun @mcmire, this is one of my favourite (favorite in the States) gems. I want to help with as many bug fixes as possible. |
@Adam89 Glad to hear! There are definitely plenty of bugs to fix and areas of the code to work on for sure. |
@mcmire I just thought of a edge case and am not sure this implementation would work for private methods that take arguments. The private method would be found but I think the args won't get passed through to the object. |
It should still work. The target method actually gets replaced with a method double, and the arguments given to that method get captured. (This is how we determine that the method got delegated.) |
@mcmire could you check if this is ready to be merged so I can start to focus on other bugs? |
expect(post_office).to delegate_method(:deliver_mail).to(:mailman) | ||
end | ||
|
||
it 'produces the correct failure message if the assertion was negated' do |
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 don't actually know if we need this test here, I'd be fine with leaving this out since we already test this in the case that the method is public.
Sorry @Adam89, thanks for nudging me. Just had a couple of things and then it should be good to merge. |
@mcmire does It look ready to be merged now? |
Just seen the label I'll squash the commits!! |
Cool. Thanks. When I get time, I'll merge this -- there are some things for 2.6.2 that need to go out first. |
Issue #526 Previously if a class delegated to a private method the `matches?` method would return `false`. This was because`respond_to?` always returns `false` for private methods, this commit fixes this by making `respond_to?` evaluate private methods.
Any chance of a new gem release for this fix? 😁 |
Yes :) 2.7.0 is now released! |
👍 |
Issue #526
Previously if a class delegated to a private method the
matches?
method wouldreturn
false
. This was becauserespond_to?
always returnsfalse
for private methods, this commit fixes this by makingrespond_to?
evaluate private methods.