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

Inherits:
Cop
  • Object
show all
Includes:
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

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

Constants included from RSpec::Util

RSpec::Util::SizeError

Constants inherited from Cop

Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE

Constants included from RSpec::Language

RSpec::Language::ALL, RSpec::Language::RSPEC

Instance Method Summary collapse

Methods included from RSpec::Util

#one

Methods included from RSpec::TopLevelDescribe

#on_send

Methods inherited from Cop

inherited, #relevant_file?

Instance Method Details

#on_top_level_describe(_node, _, second_arg) ⇒ Object



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

def on_top_level_describe(_node, (_, second_arg))
  return unless second_arg&.str_type?
  return if second_arg.str_content.start_with?('#', '.')

  add_offense(second_arg, location: :expression)
end