A better before block setup in RSpec?

Nothing to do with garbage collection, but as with a normal Ruby method, it’s better to limit the scope of a variable to the area of the code where it’s used.

There’s also the advantage that if you typo the name, attempting to use an undefined local variable will raise an error, but using an undefined instance variable will return nil.

2 Likes