Class: RuboCop::RSpec::Hook

Inherits:
Concept
  • Object
show all
Defined in:
lib/rubocop/rspec/hook.rb

Overview

Wrapper for RSpec hook

Instance Method Summary collapse

Methods inherited from Concept

#eql?, #hash, #initialize, #to_node

Methods included from Language::NodePattern

#block_pattern, #send_pattern

Constructor Details

This class inherits a constructor from RuboCop::RSpec::Concept

Instance Method Details

#example?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rubocop/rspec/hook.rb', line 23

def example?
  scope.equal?(:each)
end

#knowable_scope?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/rubocop/rspec/hook.rb', line 17

def knowable_scope?
  scope_argument.nil? ||
    scope_argument.sym_type? ||
    scope_argument.hash_type?
end

#metadataObject



37
38
39
40
41
42
# File 'lib/rubocop/rspec/hook.rb', line 37

def 
  ((node) || [])
    .map { |meta| (meta) }
    .flatten
    .inject(&:merge)
end

#nameObject



13
14
15
# File 'lib/rubocop/rspec/hook.rb', line 13

def name
  node.method_name
end

#scopeObject



27
28
29
30
31
32
33
34
35
# File 'lib/rubocop/rspec/hook.rb', line 27

def scope
  return :each if scope_argument&.hash_type?

  case scope_name
  when nil, :each, :example then :each
  when :context, :all       then :context
  when :suite               then :suite
  end
end