Class: RuboCop::Cop::RSpec::MultipleMemoizedHelpers
- Includes:
- ConfigurableMax, 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
Methods inherited from Base
Methods included from RSpec::Language::NodePattern
Instance Method Details
#on_block(node) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rubocop/cop/rspec/multiple_memoized_helpers.rb', line 92 def on_block(node) 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
103 104 105 106 |
# File 'lib/rubocop/cop/rspec/multiple_memoized_helpers.rb', line 103 def on_new_investigation super @example_group_memoized_helpers = {} end |