class RuboCop::RSpec::Hook
Wrapper for RSpec
hook
Public Instance Methods
Source
# File lib/rubocop/rspec/hook.rb, line 18 def knowable_scope? scope_argument.nil? || scope_argument.sym_type? || scope_argument.hash_type? end
Source
# File lib/rubocop/rspec/hook.rb, line 38 def metadata (extract_metadata(node) || []) .map { |meta| transform_metadata(meta) } .flatten .inject(&:merge) end
Source
# 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
Private Instance Methods
Source
# File lib/rubocop/rspec/hook.rb, line 76 def scope_argument node.send_node.first_argument end
Source
# File lib/rubocop/rspec/hook.rb, line 72 def scope_name scope_argument.to_a.first end
Source
# File lib/rubocop/rspec/hook.rb, line 51 def transform_metadata(meta) if meta.sym_type? { meta => true } else # This check is to be able to compare those two hooks: # # before(:example, :special) { ... } # before(:example, special: true) { ... } # # In the second case it's a node with a pair that has a value # of a `true_type?`. meta.pairs.map { |pair| { pair.key => transform_true(pair.value) } } end end
Source
# File lib/rubocop/rspec/hook.rb, line 66 def transform_true(node) return true if node.true_type? node end
Source
# File lib/rubocop/rspec/hook.rb, line 47 def valid_scope?(node) node.sym_type? && Language::HookScopes.all(node.value) end