Module: RuboCop::Cop::Vicenzo::RSpec::TopLevelDefinition

Includes:
PremiseTracking
Included in:
TopLevelContext, TopLevelExample, TopLevelHook, TopLevelLet, TopLevelSubject
Defined in:
lib/rubocop/cop/vicenzo/rspec/mixin/top_level_definition.rb

Overview

Shared machinery for the cops that read what a spec declares straight inside the top-level example group - the widest scope a file has, and the one every example written later inherits whether it wanted to or not.

The including cop says which children it reads, through #definition?, and how to word the offense, through MSG. A cop that names what it found overrides #message_for, and may read the name through #declared_name.

Meant for cops inheriting from RuboCop::Cop::RSpec::Base: example_group? comes from there.

Constant Summary

Constants included from PremiseTracking

PremiseTracking::SETUP_HOOKS

Instance Method Summary collapse

Methods included from PremiseTracking

#premise_name, #root_receiver_name

Instance Method Details

#on_block(node) ⇒ Object Also known as: on_numblock



21
22
23
24
25
26
27
# File 'lib/rubocop/cop/vicenzo/rspec/mixin/top_level_definition.rb', line 21

def on_block(node)
  return unless top_level_example_group?(node)

  each_child_block(node) do |child|
    add_offense(child.send_node, message: message_for(child)) if definition?(child)
  end
end