Skip to content

Commit 027d385

Browse files
authored
Merge pull request #2098 from lovro-bikic/described-class-data-define
Don't register `RSpec/DescribedClass` offenses within `Data.define` blocks
2 parents a9ed5e8 + 69cac8e commit 027d385

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Mark `RSpec/IncludeExamples` as `SafeAutoCorrect: false`. ([@yujideveloper])
66
- Fix a false positive for `RSpec/LeakyConstantDeclaration` when defining constants in explicit namespaces. ([@naveg])
77
- Add support for error matchers (`raise_exception` and `raise_error`) to `RSpec/Dialect`. ([@lovro-bikic])
8+
- Don't register offenses for `RSpec/DescribedClass` within `Data.define` blocks. ([@lovro-bikic])
89

910
## 3.6.0 (2025-04-18)
1011

lib/rubocop/cop/rspec/described_class.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ class DescribedClass < Base # rubocop:disable Metrics/ClassLength
8383

8484
# @!method common_instance_exec_closure?(node)
8585
def_node_matcher :common_instance_exec_closure?, <<~PATTERN
86-
(block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
86+
(block
87+
{
88+
(send (const nil? {:Class :Module :Struct}) :new ...)
89+
(send (const nil? :Data) :define ...)
90+
}
91+
...
92+
)
8793
PATTERN
8894

8995
# @!method rspec_block?(node)

spec/rubocop/cop/rspec/described_class_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ module Foo
178178
Class.new { foo = MyClass }
179179
Module.new { bar = MyClass }
180180
Struct.new { lol = MyClass }
181+
Data.define { dat = MyClass }
181182
182183
def method
183184
include MyClass

0 commit comments

Comments
 (0)