Skip to content

Commit

Permalink
Merge pull request #1976 from corsonknowles/test_and_deprecate_top_le…
Browse files Browse the repository at this point in the history
…vel_group_mixin_method

Deprecate top_level_group? and test it in a Cop class
  • Loading branch information
bquorning authored Oct 26, 2024
2 parents 2a803ff + a3eccd0 commit a7d140d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

- Deprecate `top_level_group?` method from `TopLevelGroup` mixin as all of its callers were intentionally removed from `Rubocop/RSpec`. ([@corsonknowles])

## 3.2.0 (2024-10-26)

- Fix `RSpec/VoidExpect` to only operate inside an example block. ([@corsonknowles])
Expand Down
7 changes: 7 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,10 @@ 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 +32,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 a7d140d

Please sign in to comment.