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
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.
  • Loading branch information
corsonknowles committed Oct 25, 2024
1 parent 530af44 commit b7d0877
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix `RSpec/VoidExpect` to only operate inside an example block. ([@corsonknowles])
- Change `RSpec/ContextWording` cop to always report an offense when both `Prefixes` and `AllowedPatterns` are empty. ([@ydah])
- Fix an error for `RSpec/ChangeByZero` when `change (...) .by (0)` and `change (...)`, concatenated with `and` and `or`. ([@ydah])
- Deprecate `top_level_group?` method from `TopLevelGroup` mixin as all of its callers were intentionally removed from `Rubocop/RSpec`. ([@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,9 @@ module RSpec
module TopLevelGroup
extend RuboCop::NodePattern::Macros

DEPRECATED_MODULE_METHOD_WARNING =
'top_level_group? is deprecated and will be ' \
'removed in the next major version of rubocop_rspec.'
def on_new_investigation
super

Expand All @@ -28,7 +31,10 @@ def on_top_level_example_group(_node); end

def on_top_level_group(_node); end

# @private
# @deprecated All callers of this method have been removed.
def top_level_group?(node)
warn DEPRECATED_MODULE_METHOD_WARNING, uplevel: 1
top_level_groups.include?(node)
end

Expand Down
24 changes: 24 additions & 0 deletions spec/rubocop/cop/rspec/mixin/top_level_group_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

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

0 comments on commit b7d0877

Please sign in to comment.