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

Inherits:
RuboCop::Cop show all
Includes:
RSpec::SpecOnly, RSpec::TopLevelDescribe, RSpec::Util
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

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

Constants included from RSpec::SpecOnly

RSpec::SpecOnly::DEFAULT_CONFIGURATION

Constants included from RSpec::Util

RSpec::Util::SizeError

Instance Method Summary collapse

Methods included from RSpec::SpecOnly

#relevant_file?

Methods included from RSpec::TopLevelDescribe

#on_send

Methods included from RSpec::Util

#one

Instance Method Details

#on_top_level_describe(_node, _, second_arg) ⇒ Object



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

def on_top_level_describe(_node, (_, second_arg))
  return unless second_arg && second_arg.type.equal?(:str)
  return if METHOD_STRING_MATCHER =~ one(second_arg.children)

  add_offense(second_arg, :expression, MESSAGE)
end