Class: RuboCop::Cop::RSpec::DescribedClassModuleWrapping

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

Overview

Avoid opening modules and defining specs within them.

Examples:

# bad
module MyModule
  RSpec.describe MyClass do
    # ...
  end
end

# good
RSpec.describe MyModule::MyClass do
  # ...
end

See Also:

Constant Summary collapse

MSG =
'Avoid opening modules and defining specs within them.'

Instance Method Summary collapse

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

#include_rspec_blocks?(node) ⇒ Object



26
27
28
# File 'lib/rubocop/cop/rspec/described_class_module_wrapping.rb', line 26

def_node_search :include_rspec_blocks?, <<~PATTERN
  ({block numblock} (send #explicit_rspec? #ExampleGroups.all ...) ...)
PATTERN

#on_module(node) ⇒ Object



30
31
32
33
34
# File 'lib/rubocop/cop/rspec/described_class_module_wrapping.rb', line 30

def on_module(node)
  return unless include_rspec_blocks?(node)

  add_offense(node)
end