Rubocop-rspec: Potentially misleading guidance for InstanceVariable cop

Created on 25 May 2017  Â·  4Comments  Â·  Source: rubocop-hq/rubocop-rspec

"Use let instead of an instance variable" doesn't make sense in cases where an instance variable is used unnecessarily rather than a local variable. For example within a before block, assuming @foo isn't used anywhere else:

before do
  @foo = 'bar'
  widget.stub(@foo)
end

Most helpful comment

This sounds just right.
@bquorning @Darhazer WDYT? I can make this change quickly.

All 4 comments

It might still be used somewhere in the shared example, and we won't be able to detect that usage.
Did you have a more generic message in mind, like "Don't use an instance variable"?

How about: "Avoid instance variables – use let, a method call, or a local variable (if possible)"

This sounds just right.
@bquorning @Darhazer WDYT? I can make this change quickly.

I like it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mockdeep picture mockdeep  Â·  6Comments

luizkowalski picture luizkowalski  Â·  5Comments

pirj picture pirj  Â·  4Comments

bbatsov picture bbatsov  Â·  7Comments

MadhuriShres picture MadhuriShres  Â·  5Comments