-
-
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
Deprecate top_level_group? and test it in a Cop class #1976
Deprecate top_level_group? and test it in a Cop class #1976
Conversation
6a1812f
to
d1de0e7
Compare
fdcb6c8
to
c99e4b6
Compare
@@ -29,6 +34,7 @@ def on_top_level_example_group(_node); end | |||
def on_top_level_group(_node); end | |||
|
|||
def top_level_group?(node) |
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.
def top_level_group?(node) | |
# @private | |
# @deprecated <some description on how to replace> | |
def top_level_group?(node) |
This is more a reminder for us not to forget to remove in 4.0
Should we file a ticket?
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.
Like an Issue? Or is there an internal ticketing system?
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 added the @deprecated
declaration, but I'm still not sure what filing a ticket entails.
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.
Yeah, we just use issues. I created a 4.0
milestone and opened #1986.
DEPRECATED_PRIVATE_METHOD_WARNING = | ||
'top_level_group? is deprecated and will be ' \ | ||
'removed in the next major version of Rubocop/RSpec.' \ | ||
'Please copy the method if you need it for your mixin.' |
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.
Is it a good advice to copy?
We’ve stopped using it for a reason?
Was that performance? Should we say to consider using the hook instead?
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 actually don't know what the hook is. Do you want to suggest language?
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 removed the copying advice
@@ -29,6 +34,7 @@ def on_top_level_example_group(_node); end | |||
def on_top_level_group(_node); end | |||
|
|||
def top_level_group?(node) | |||
warn DEPRECATED_PRIVATE_METHOD_WARNING | |||
top_level_groups.include?(node) | |||
end | |||
|
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.
Something feels off about the node.children
line.
I vaguely recall that a single-statement block and a multi-statement block’s AST are different (yuck!). Will the result be correct in both cases?
Like
foo { RSpec.describe { } }
vs foo { RSpec.describe { }; RSpec.shared_examples { } }
?
Unrelated to this PR, just an observation.
Might as well be a false alarm, and I apologise in advance.
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.
Sounds like more specs are needed!
c99e4b6
to
3155c0e
Compare
You’ll need to rebase to fix the failing config/docs CI check. |
3155c0e
to
5726962
Compare
Rebased and ready to go. |
@ydah or @bquorning Would either of you like to be the 2nd reviewer on this? |
@@ -7,6 +7,9 @@ module RSpec | |||
module TopLevelGroup | |||
extend RuboCop::NodePattern::Macros | |||
|
|||
DEPRECATED_PRIVATE_METHOD_WARNING = | |||
'top_level_group? is deprecated and will be ' \ | |||
'removed in the next major version of Rubocop/RSpec.' |
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.
'removed in the next major version of Rubocop/RSpec.' | |
'removed in the next major version of rubocop_rspec.' | |
def top_level_group?(node) | ||
warn DEPRECATED_PRIVATE_METHOD_WARNING |
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.
In RuboCop they use Rainbow
to make yellow warnings. I’m a bit hesitant to add it as a dependency to our gem, but I think we should use the uplevel
keyword argument that they also use:
warn DEPRECATED_PRIVATE_METHOD_WARNING | |
warn DEPRECATED_PRIVATE_METHOD_WARNING, uplevel: 1 |
That also prints the line that called the method, plus the word warning
.
|
||
context 'with mixin tests' do | ||
describe '#top_level_group?' do | ||
subject(:cop_with_top_level_group_mixin) do | ||
described_class.new | ||
end | ||
|
||
it 'warns because it is deprecated' do | ||
# rubocop:disable RSpec/SubjectStub | ||
allow(cop_with_top_level_group_mixin).to receive(:warn) | ||
allow(cop_with_top_level_group_mixin).to receive(:top_level_groups) | ||
.and_return([]) | ||
|
||
cop_with_top_level_group_mixin.send(:top_level_group?, nil) | ||
expect(cop_with_top_level_group_mixin).to have_received(:warn) | ||
# rubocop:enable RSpec/SubjectStub | ||
end | ||
end | ||
end |
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 can add a new file testing only the module you changed – and that way we can (almost) avoid stubbing. E.g.:
# spec/rubocop/cop/rspec/mixin/top_level_group_spec.rb
RSpec.describe RuboCop::Cop::RSpec::TopLevelGroup do
describe '#top_level_group?' do
let(:stub_class) do
Class.new do
include RuboCop::Cop::RSpec::TopLevelGroup
def initialize
@top_level_groups = []
end
def test_top_level_group
top_level_group?(nil)
end
end
end
it 'warns because it is deprecated' do
expect { stub_class.new.test_top_level_group }.to \
output(/warning: top_level_group\? is deprecated/).to_stderr
end
end
end
In this PR, we add a deprecation message for top_level_group?, which has no callers in current Rubocop/RSpec. The specs for this change complete line coverage for this repo.
e1a276b
to
b7d0877
Compare
This would have locked in coverage: But I can't chase a moving target at this speed. |
a0e69f8
to
a3eccd0
Compare
In this PR, we add a deprecation message for
top_level_group?
, which has no callers in currentRubocop/RSpec
.top_level_group?
was confirmed unused by @bquorning here:We test this method using some stubbing in a Cop class that includes the mixin.
The specs can be removed along with the method in the next Major version update.
Split from:
This PR serves the goal of completing line coverage for this repo
and unblockshelps unblock: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).If you have created a new cop:
config/default.yml
.Enabled: pending
inconfig/default.yml
.Enabled: true
in.rubocop.yml
.VersionAdded: "<<next>>"
indefault/config.yml
.If you have modified an existing cop's configuration options:
VersionChanged: "<<next>>"
inconfig/default.yml
.