Class: RuboCop::Cop::RSpec::MultipleDescribes

Inherits:
Base
  • Object
show all
Includes:
TopLevelGroup
Defined in:
lib/rubocop/cop/rspec/multiple_describes.rb

Overview

Checks for multiple top-level example groups.

Multiple descriptions for the same class or module should either be nested or separated into different test files.

Examples:

# bad
describe MyClass, '.do_something' do
end
describe MyClass, '.do_something_else' do
end

# good
describe MyClass do
  describe '.do_something' do
  end
  describe '.do_something_else' do
  end
end

Constant Summary collapse

MSG =
'Do not use multiple top-level example groups - try to nest them.'

Constants included from TopLevelGroup

TopLevelGroup::DEPRECATED_MODULE_METHOD_WARNING

Instance Method Summary collapse

Methods included from TopLevelGroup

#on_new_investigation, #top_level_groups

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language

#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?

Instance Method Details

#on_top_level_group(node) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/rubocop/cop/rspec/multiple_describes.rb', line 31

def on_top_level_group(node)
  top_level_example_groups =
    top_level_groups.select { |group| example_group?(group) }

  return if top_level_example_groups.one?
  return unless top_level_example_groups.first.equal?(node)

  add_offense(node.send_node)
end