Class: RuboCop::Cop::RSpec::InstanceVariable
- 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).'
- EXAMPLE_GROUP_METHODS =
ExampleGroups::ALL + SharedGroups::ALL
Constants inherited from Cop
Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
RSpec::Language::ALL, RSpec::Language::RSPEC
Instance Method Summary collapse
Methods inherited from Cop
Instance Method Details
#on_block(node) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rubocop/cop/rspec/instance_variable.rb', line 65 def on_block(node) return unless spec_group?(node) ivar_usage(node) do |ivar, name| return if inside_dynamic_class?(ivar) return if assignment_only? && !ivar_assigned?(node, name) add_offense(ivar) end end |