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

Inherits:
RuboCop::Cop
  • Object
show all
Includes:
RSpec::SpecOnly, RSpec::TopLevelDescribe
Defined in:
lib/rubocop/cop/rspec/multiple_describes.rb

Overview

Checks for multiple top level describes.

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
  describe '.do_something' do
  end
  describe '.do_something_else' do
  end
end

Constant Summary collapse

MSG =
'Do not use multiple top level describes - ' \
'try to nest them.'.freeze

Constants included from RSpec::SpecOnly

RSpec::SpecOnly::DEFAULT_CONFIGURATION

Instance Method Summary collapse

Methods included from RSpec::SpecOnly

#relevant_file?

Methods included from RSpec::TopLevelDescribe

#on_send

Instance Method Details

#on_top_level_describe(node, _args) ⇒ Object



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

def on_top_level_describe(node, _args)
  return if single_top_level_describe?
  return unless top_level_nodes.first.equal?(node)

  add_offense(node, :expression)
end