class RuboCop::Cop::RSpec::InstanceVariable


end
it { expect(foo).to be_empty }
let(:foo) { [] }
describe MyClass do
# good
end
it { expect(@foo).to be_empty }
describe MyClass do
# allowed
end
it { expect(@foo).to be_empty }
before { @foo = [] }
describe MyClass do
# bad
AssignmentOnly: false
RSpec/InstanceVariable:
# rubocop.yml
@example with AssignmentOnly configuration
end
it { expect(foo).to be_empty }
let(:foo) { [] }
describe MyClass do
# good
end
it { expect(@foo).to be_empty }
before { @foo = [] }
describe MyClass do
# bad
@example
the spec
variable usage if the instance variable is also assigned within
will configure the cop to only register offenses on instance
This cop can be configured with the option ‘AssignmentOnly` which
Checks for instance variable usage in specs.

def assignment_only?

def assignment_only?
  cop_config['AssignmentOnly']
end

def on_block(node)

def on_block(node)
  return unless spec_group?(node)
  ivar_usage(node) do |ivar, name|
    return if assignment_only? && !ivar_assigned?(node, name)
    add_offense(ivar, location: :expression)
  end
end