Class: RuboCop::Cop::RSpec::DescribeMethod

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

Overview

Checks that the second argument to `describe` specifies a method.

Examples:

# bad
describe MyClass, 'do something' do
end

# good
describe MyClass, '#my_instance_method' do
end

describe MyClass, '.my_class_method' do
end

Constant Summary collapse

MSG =
'The second argument to describe should be the method '\
"being tested. '#instance' or '.class'."

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

#block_pattern, #send_pattern

Instance Method Details

#on_top_level_group(node) ⇒ Object


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

def on_top_level_group(node)
  second_argument = second_argument(node)

  return unless second_argument
  return if second_argument.str_content.start_with?('#', '.')

  add_offense(second_argument)
end