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::NodePattern

#block_pattern, #send_pattern

Methods included from RSpec::Language

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

Instance Method Details

#find_rspec_blocks(node) ⇒ Object


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

def_node_search :find_rspec_blocks, block_pattern('#ExampleGroups.all')

#on_module(node) ⇒ Object


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

def on_module(node)
  find_rspec_blocks(node) do
    add_offense(node)
  end
end