I approve of this question, but in the end I answer the question myself.
Describe the differences first
The let method, when used, does not initialize the variable until it is specified in the test, which distinguishes it from @instance variables , which are initialized from the very beginning.
In general, there is not much uncertainty. Use @instance variables if you want to make sure the let object is initialized. But, on the other hand, it can be done the same with let! , so there is no obvious reason to use @instance variable .
In conclusion, for me there is an obvious reason to use @instance variable over let , but there is no obvious reason to use @instance variables over let!
@instance variables takes longer to load and, using them, can lead to undesirable code complexity, which could have been avoided using let or let!
You can also take a look at these two answers, perhaps this will give you additional information:
When to use RSpec let ()?
RSpec: What is the difference between let and a before blocks?
Aleks Mar 26 '13 at 13:41 2013-03-26 13:41
source share