-
-
Notifications
You must be signed in to change notification settings - Fork 277
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 a false positive for RSpec/RepeatedSubjectCall
#1822
Conversation
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.
A nice simplification and a quick fix. Thank you!
walker = subject_node | ||
def detect_offense(subject_node) | ||
subject_node.each_ancestor(:block) do |block| | ||
next if subject_node.chained? |
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 have never seen this method. Is it old enough for us to be sure it will be there with a minimum required rubocop and rubocop-ast versions we require?
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 was there like forever. I just wonder if we should not just skip the whole each_ancestor in this case, instead of skipping each iteration 😅
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.
we should not just skip the whole each_ancestor in this case, instead of skipping each iteration 😅
Indeed! Thank you catching 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.
I have no objections against this change.
The original spec however is light on use cases. What happens for instance if you access subject in a hook, let's say configuring a stub like allow(Foo).to receive(:bar).and_return(subject)
(which might also use block synax allow(Foo).to receive(:bar) { subject }
. It's hard to tell from reading the code alone
Indeed. I'll make a follow-up PR. |
Fix: #1821
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).