Skip to content

Commit 6ff1c39

Browse files
committed
Fix a false positive for RSpec/DescribedClass when SkipBlocks is true and numblocks are used
1 parent 6fca833 commit 6ff1c39

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Master (Unreleased)
44

5+
- Fix a false positive for `RSpec/DescribedClass` when `SkipBlocks` is true and numblocks are used. ([@earlopain])
6+
57
## 3.5.0 (2025-02-16)
68

79
- Don't let `RSpec/PredicateMatcher` replace `respond_to?` with two arguments with the RSpec `respond_to` matcher. ([@bquorning])

Diff for: lib/rubocop/cop/rspec/described_class.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ def scope_change?(node)
153153
end
154154

155155
def skippable_block?(node)
156-
node.block_type? && !rspec_block?(node) && cop_config['SkipBlocks']
156+
return unless cop_config['SkipBlocks']
157+
158+
node.any_block_type? && !rspec_block?(node)
157159
end
158160

159161
def only_static_constants?

Diff for: spec/rubocop/cop/rspec/described_class_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@
2424
end
2525
RUBY
2626
end
27+
28+
it 'ignores offenses within non-rspec numblocks' do
29+
expect_offense(<<~RUBY)
30+
describe MyClass do
31+
controller(ApplicationController) do
32+
_1
33+
bar = MyClass
34+
end
35+
36+
before do
37+
MyClass
38+
^^^^^^^ Use `described_class` instead of `MyClass`.
39+
40+
Foo.custom_block do
41+
MyClass
42+
end
43+
end
44+
end
45+
RUBY
46+
end
2747
end
2848

2949
context 'when SkipBlocks is `false`' do

0 commit comments

Comments
 (0)