Class: RuboCop::Cop::RSpec::InstanceVariable
- Includes:
- TopLevelGroup
- Defined in:
- lib/rubocop/cop/rspec/instance_variable.rb
Overview
Checks for instance variable usage in specs.
This cop can be configured with the option ‘AssignmentOnly` which will configure the cop to only register offenses on instance variable usage if the instance variable is also assigned within the spec
Constant Summary collapse
- MSG =
'Avoid instance variables – use let, ' \ 'a method call, or a local variable (if possible).'
Instance Method Summary collapse
Methods included from TopLevelGroup
#on_new_investigation, #top_level_groups
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Instance Method Details
#on_top_level_group(node) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/rubocop/cop/rspec/instance_variable.rb', line 70 def on_top_level_group(node) ivar_usage(node) do |ivar, name| next if valid_usage?(ivar) next if assignment_only? && !ivar_assigned?(node, name) add_offense(ivar) end end |