-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preference on instance variables in tests #2
Comments
Instance variables should be avoided except in very specific circumstances (LevelUp, while using Test::Unit + shoulda, had an explicit style which recommends instance variables, for example). The only state that would possibly carry over in RSpec would be data structures created in the In the Intro to Test-Driven Rails workshop, I recommend against instance variables in steps for a number of reasons. First, steps which are already coupled to each other based on application state are additionally coupled when you start using instance variables. The steps I've seen using ivars end up doing something along the lines of I feel the same way about ivars in Cucumber steps as I do in RSpec integration tests - instance variables can be used there to set up state and write really sexy methods that refer to the variables, but I think that the issues I mentioned with Cucumber steps carry through here as well. Generally, I try to avoid mutation as much as possible in all aspects of my code, specs and features included. |
The current style guide already advises against using |
I generally don't use instance variables in tests - I believe this was part of Josh's TDD Workshop curricula but I'm not sure.
Is there a stance on this? If so, should go into the testing section.
The text was updated successfully, but these errors were encountered: