Class: RuboCop::RSpec::Hook
Overview
Instance Method Summary
collapse
Methods inherited from Concept
#eql?, #hash, #initialize, #to_node
Methods included from Language
#example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#example? ⇒ Boolean
24
25
26
|
# File 'lib/rubocop/rspec/hook.rb', line 24
def example?
scope.equal?(:each)
end
|
8
9
10
11
12
|
# File 'lib/rubocop/rspec/hook.rb', line 8
def_node_matcher :extract_metadata, <<~PATTERN
(block
(send _ _ #valid_scope? ? $...) ...
)
PATTERN
|
#knowable_scope? ⇒ Boolean
18
19
20
21
22
|
# File 'lib/rubocop/rspec/hook.rb', line 18
def knowable_scope?
scope_argument.nil? ||
scope_argument.sym_type? ||
scope_argument.hash_type?
end
|
38
39
40
41
42
43
|
# File 'lib/rubocop/rspec/hook.rb', line 38
def metadata
((node) || [])
.map { |meta| transform_metadata(meta) }
.flatten
.inject(&:merge)
end
|
#name ⇒ Object
14
15
16
|
# File 'lib/rubocop/rspec/hook.rb', line 14
def name
node.method_name
end
|
#scope ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/rubocop/rspec/hook.rb', line 28
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
|