-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
RSpec/SubjectStub. Add top level group callback #932
RSpec/SubjectStub. Add top level group callback #932
Conversation
cad26f6
to
7a0a6b6
Compare
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.
Even more cleaner than the previous implementation 💯
@pirj Fixed all the issues |
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.
Perfect! 😗 👌
lib/rubocop/rspec/top_level_group.rb
Outdated
end | ||
|
||
def top_level_nodes | ||
@top_level_nodes ||= |
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.
Minor: does it make sense to memoize it? It's only called once from a method that is also memoized.
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.
Perfect! Thank you.
top_level_nodes.select { |n| example_or_shared_group?(n) } | ||
end | ||
|
||
def top_level_nodes |
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.
At some point, we may want to DRY this between the different modules.
Also, top_level_describe seems to be a special case on top_level_group.
For now I'm fine with keeping it as it is
Merging without consensus, since this change has been discussed in the past, and only affects one cop. Thank you again, @andrykonchin ! |
Why? - it was slow #925 (comment) - it ignored non-describe top-level example groups #925 (comment) `TopLevelGroup` is a modern replacement for `TopLevelDescribe`. Examples how to migrate cops from TopLevelDescribe to TopLevelGroup: - #932 - #977
(ExampleGroups::ALL + SharedGroups::ALL).block_pattern | ||
|
||
def on_block(node) | ||
return unless respond_to?(:on_top_level_group) |
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.
An afterthought.
I understand that this guard statement is on the very top to avoid a quite expensive check done in top_level_group?
.
But is it really necessary? If a cop includes TopLevelGroup
, that means it defines a on_top_level_group
method? Otherwise why would it include TopLevelGroup
?
Or am I missing something?
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.
TBH I just copied this approach from TopLevelDescribe
module. I don't see any benefit in having such condition here.
Why? - it was slow #925 (comment) - it ignored non-describe top-level example groups #925 (comment) `TopLevelGroup` is a modern replacement for `TopLevelDescribe`. Examples how to migrate cops from TopLevelDescribe to TopLevelGroup: - #932 - #977
Why? - it was slow #925 (comment) - it ignored non-describe top-level example groups #925 (comment) `TopLevelGroup` is a modern replacement for `TopLevelDescribe`. Examples how to migrate cops from TopLevelDescribe to TopLevelGroup: - #932 - #977
Why? - it was slow #925 (comment) - it ignored non-describe top-level example groups #925 (comment) `TopLevelGroup` is a modern replacement for `TopLevelDescribe`. Examples how to migrate cops from TopLevelDescribe to TopLevelGroup: - #932 - #977
Why? - it was slow #925 (comment) - it ignored non-describe top-level example groups #925 (comment) `TopLevelGroup` is a modern replacement for `TopLevelDescribe`. Examples how to migrate cops from TopLevelDescribe to TopLevelGroup: - #932 - #977
Why? - it was slow rubocop/rubocop-rspec#925 (comment) - it ignored non-describe top-level example groups rubocop/rubocop-rspec#925 (comment) `TopLevelGroup` is a modern replacement for `TopLevelDescribe`. Examples how to migrate cops from TopLevelDescribe to TopLevelGroup: - rubocop/rubocop-rspec#932 - rubocop/rubocop-rspec#977
Why? - it was slow rubocop/rubocop-rspec#925 (comment) - it ignored non-describe top-level example groups rubocop/rubocop-rspec#925 (comment) `TopLevelGroup` is a modern replacement for `TopLevelDescribe`. Examples how to migrate cops from TopLevelDescribe to TopLevelGroup: - rubocop/rubocop-rspec#932 - rubocop/rubocop-rspec#977
Why? - it was slow rubocop/rubocop-rspec#925 (comment) - it ignored non-describe top-level example groups rubocop/rubocop-rspec#925 (comment) `TopLevelGroup` is a modern replacement for `TopLevelDescribe`. Examples how to migrate cops from TopLevelDescribe to TopLevelGroup: - rubocop/rubocop-rspec#932 - rubocop/rubocop-rspec#977
It's a followup of #925 and it addresses the following issue #925 (comment)
Changes:
The goal of TopLevelGroup is to handle all the possible example and shared groups in a spec file. It calls
on_top_level_group
callback for every top-leveldescribe
,context
,feature
,shared context
... group.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).