Class: RuboCop::Cop::RSpec::MultipleMemoizedHelpers
- Includes:
- Variable
- Defined in:
- lib/rubocop/cop/rspec/multiple_memoized_helpers.rb
Overview
Checks if example groups contain too many let and subject calls.
This cop is configurable using the Max option and the AllowSubject which will configure the cop to only register offenses on calls to let and not calls to subject.
Constant Summary collapse
- MSG =
'Example group has too many memoized helpers [%<count>d/%<max>d]'
Constants included from Variable
Variable::Helpers, Variable::Subjects
Instance Method Summary collapse
-
#on_block(node) ⇒ Object
rubocop:disable InternalAffairs/NumblockHandler.
- #on_new_investigation ⇒ Object
Methods included from Variable
Methods inherited from Base
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?
Instance Method Details
#on_block(node) ⇒ Object
rubocop:disable InternalAffairs/NumblockHandler
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rubocop/cop/rspec/multiple_memoized_helpers.rb', line 91 def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler return unless spec_group?(node) count = all_helpers(node).uniq.count return if count <= max self.max = count add_offense(node, message: format(MSG, count: count, max: max)) end |
#on_new_investigation ⇒ Object
102 103 104 105 |
# File 'lib/rubocop/cop/rspec/multiple_memoized_helpers.rb', line 102 def on_new_investigation super @example_group_memoized_helpers = {} end |