Skip to content

Commit

Permalink
Deprecate top_level_group? and test it in a Cop class
Browse files Browse the repository at this point in the history
  • Loading branch information
corsonknowles committed Oct 14, 2024
1 parent 961e544 commit d1de0e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Master (Unreleased)
- Deprecate `top_level_group?` private method on TopLevelGroup mixin. ([@corsonknowles])

## 3.1.0 (2024-10-01)

Expand Down
6 changes: 6 additions & 0 deletions lib/rubocop/cop/rspec/mixin/top_level_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ module RSpec
module TopLevelGroup
extend RuboCop::NodePattern::Macros

DEPRECATED_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 you mixin.'

def on_new_investigation
super

Expand All @@ -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_METHOD_WARNING
top_level_groups.include?(node)
end

Expand Down
19 changes: 19 additions & 0 deletions spec/rubocop/cop/rspec/describe_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,23 @@
RUBY
end
end

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
end

0 comments on commit d1de0e7

Please sign in to comment.