Class: RuboCop::Cop::RSpec::DescribeClass

Inherits:
Cop
  • Object
show all
Includes:
RSpec::TopLevelDescribe
Defined in:
lib/rubocop/cop/rspec/describe_class.rb

Overview

Check that the first argument to the top level describe is a constant.

Examples:

# bad
describe 'Do something' do
end

# good
describe TestedClass do
end

describe "A feature example", type: :feature do
end

Constant Summary collapse

MSG =
'The first argument to describe should be '\
'the class or module being tested.'

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

#on_send

Methods inherited from Cop

inherited, #relevant_file?

Instance Method Details

#on_top_level_describe(node, args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/rubocop/cop/rspec/describe_class.rb', line 47

def on_top_level_describe(node, args)
  return if shared_group?(root_node)
  return if valid_describe?(node)

  (node) do |pairs|
    return if pairs.any?(&method(:rails_metadata?))
  end

  add_offense(args.first, location: :expression)
end