Skip to content

Commit 7711c76

Browse files
committed
Ignore example groups defined inside examples
Found a lot of this in rspec-core and rspec-mocks
1 parent 6a30a41 commit 7711c76

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/rubocop/cop/rspec/empty_example_group.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class EmptyExampleGroup < Base
161161

162162
def on_block(node)
163163
return if node.each_ancestor(:def, :defs).any?
164+
return if node.each_ancestor(:block).any? { |block| example?(block) }
164165

165166
example_group_body(node) do |body|
166167
add_offense(node.send_node) unless examples?(body)

spec/rubocop/cop/rspec/empty_example_group_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,15 @@ def without_yaml_loaded(&block)
282282
end
283283
RUBY
284284
end
285+
286+
it 'ignores example groups inside examples' do
287+
expect_no_offenses(<<~RUBY)
288+
RSpec.describe 'rspec-core' do
289+
it 'runs an example group' do
290+
group = RSpec.describe { }
291+
group.run
292+
end
293+
end
294+
RUBY
295+
end
285296
end

0 commit comments

Comments
 (0)