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

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

Overview

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

It can be configured to ignore strings when certain metadata is passed.

Ignores Rails and Aruba `type` metadata by default.

Examples:

`IgnoredMetadata` configuration


# .rubocop.yml
# RSpec/DescribeClass:
#   IgnoredMetadata:
#     type:
#       - request
#       - controller
# bad
describe 'Do something' do
end

# good
describe TestedClass do
  subject { described_class }
end

describe 'TestedClass::VERSION' do
  subject { Object.const_get(self.class.description) }
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.'

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


55
56
57
58
59
60
61
# File 'lib/rubocop/cop/rspec/describe_class.rb', line 55

def on_top_level_group(node)
  return if example_group_with_ignored_metadata?(node.send_node)

  not_a_const_described(node.send_node) do |described|
    add_offense(described)
  end
end