Class: RuboCop::Cop::RSpec::DescribeClass
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::RSpec::DescribeClass
- Includes:
- RSpec::TopLevelDescribe
- Defined in:
- lib/rubocop/cop/rspec/describe_class.rb
Overview
Check that the first argument to the top level describe is the tested class or module.
Constant Summary collapse
- REQUEST_PAIR =
s(:pair, s(:sym, :type), s(:sym, :request))
- FEATURE_PAIR =
s(:pair, s(:sym, :type), s(:sym, :feature))
- ROUTING_PAIR =
s(:pair, s(:sym, :type), s(:sym, :routing))
- VIEW_PAIR =
s(:pair, s(:sym, :type), s(:sym, :view))
- MESSAGE =
'The first argument to describe should be the class or ' \ 'module being tested.'.freeze
Instance Method Summary collapse
Methods included from RSpec::TopLevelDescribe
Instance Method Details
#on_top_level_describe(_node, args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubocop/cop/rspec/describe_class.rb', line 32 def on_top_level_describe(_node, args) return if args[0] && args[0].type == :const return if args[1..-1].any? do |arg| next unless arg.hash_type? arg.children.any? do |n| [REQUEST_PAIR, FEATURE_PAIR, ROUTING_PAIR, VIEW_PAIR].include?(n) end end add_offense(args[0], :expression, MESSAGE) end |