Skip to content

Commit b7d0877

Browse files
committed
Deprecate top_level_group? and test it in a Cop class
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.
1 parent 530af44 commit b7d0877

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Fix `RSpec/VoidExpect` to only operate inside an example block. ([@corsonknowles])
66
- Change `RSpec/ContextWording` cop to always report an offense when both `Prefixes` and `AllowedPatterns` are empty. ([@ydah])
77
- Fix an error for `RSpec/ChangeByZero` when `change (...) .by (0)` and `change (...)`, concatenated with `and` and `or`. ([@ydah])
8+
- Deprecate `top_level_group?` method from `TopLevelGroup` mixin as all of its callers were intentionally removed from `Rubocop/RSpec`. ([@corsonknowles])
89

910
## 3.1.0 (2024-10-01)
1011

lib/rubocop/cop/rspec/mixin/top_level_group.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module RSpec
77
module TopLevelGroup
88
extend RuboCop::NodePattern::Macros
99

10+
DEPRECATED_MODULE_METHOD_WARNING =
11+
'top_level_group? is deprecated and will be ' \
12+
'removed in the next major version of rubocop_rspec.'
1013
def on_new_investigation
1114
super
1215

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

2932
def on_top_level_group(_node); end
3033

34+
# @private
35+
# @deprecated All callers of this method have been removed.
3136
def top_level_group?(node)
37+
warn DEPRECATED_MODULE_METHOD_WARNING, uplevel: 1
3238
top_level_groups.include?(node)
3339
end
3440

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe RuboCop::Cop::RSpec::TopLevelGroup do
4+
describe '#top_level_group?' do
5+
let(:stub_class) do
6+
Class.new do
7+
include RuboCop::Cop::RSpec::TopLevelGroup
8+
9+
def initialize
10+
@top_level_groups = []
11+
end
12+
13+
def test_top_level_group
14+
top_level_group?(nil)
15+
end
16+
end
17+
end
18+
19+
it 'warns because it is deprecated' do
20+
expect { stub_class.new.test_top_level_group }.to \
21+
output(/warning: top_level_group\? is deprecated/).to_stderr
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)