Class: RuboCop::Cop::RSpec::DescribeClass
- 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.
Constant Summary collapse
- MSG =
'The first argument to describe should be ' \ 'the class or module being tested.'
Constants included from TopLevelGroup
TopLevelGroup::DEPRECATED_MODULE_METHOD_WARNING
Instance Method Summary collapse
- #example_group_with_ignored_metadata?(node) ⇒ Object
- #not_a_const_described(node) ⇒ Object
- #on_top_level_group(node) ⇒ Object
- #sym_pair(node) ⇒ Object
Methods included from TopLevelGroup
#on_new_investigation, #top_level_groups
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#example_group_with_ignored_metadata?(node) ⇒ Object
44 45 46 |
# File 'lib/rubocop/cop/rspec/describe_class.rb', line 44 def_node_matcher :example_group_with_ignored_metadata?, <<~PATTERN (send #rspec? :describe ... (hash <#ignored_metadata? ...>)) PATTERN |
#not_a_const_described(node) ⇒ Object
49 50 51 |
# File 'lib/rubocop/cop/rspec/describe_class.rb', line 49 def_node_matcher :not_a_const_described, <<~PATTERN (send #rspec? :describe $[!const !#string_constant?] ...) PATTERN |
#on_top_level_group(node) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/rubocop/cop/rspec/describe_class.rb', line 58 def on_top_level_group(node) return if (node.send_node) not_a_const_described(node.send_node) do |described| add_offense(described) end end |
#sym_pair(node) ⇒ Object
54 55 56 |
# File 'lib/rubocop/cop/rspec/describe_class.rb', line 54 def_node_matcher :sym_pair, <<~PATTERN (pair $sym $sym) PATTERN |