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

Inherits:
RuboCop::Cop show all
Includes:
RSpec::TopLevelDescribe
Defined in:
lib/rubocop/cop/rspec/describe_method.rb

Overview

Checks that the second argument to the top level describe is the tested method name.

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

MESSAGE =
'The second argument to describe should be the method ' \
"being tested. '#instance' or '.class'".freeze
METHOD_STRING_MATCHER =
/^[\#\.].+/

Instance Method Summary collapse

Methods included from RSpec::TopLevelDescribe

#on_send

Instance Method Details

#on_top_level_describe(_node, args) ⇒ Object



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

def on_top_level_describe(_node, args)
  second_arg = args[1]
  return unless second_arg && second_arg.type == :str
  return if METHOD_STRING_MATCHER =~ second_arg.children.first

  add_offense(second_arg, :expression, MESSAGE)
end