In RSPEC, the behavior of Let is to memoize across a single example ( it block ), but in some cases this can lead to some potentially nasty side effects as far as timing.
I've noticed that if you manage to try and create anything that would be considered expensive, such as a large mock, the entirety of the object creation will be repeated each and every single example it's called in.
The first step to troubleshooting this was hacking the mock data down to size, which cut a majority of the run time down from ~30 seconds to ~.08 seconds. That given, by transferring a let variable that's being called 3+ times without any form of mutation to an instance, the speed can be increased even more (-0.02 to -0.04 in this case).
Normally, it could be reasoned that the lazy evaluation is desirable and that such things are a price of safety in some cases. In the context of a large test suite (3000+ tests) a difference of even 0.01-0.02 seconds often enough can lead to 20-30 seconds of bloat. Of course this is arbitrary numbering in some cases, but you can see why this would be undesirable and create a compounding problem.
The questions I have are:
- In what cases is let no longer a viable option?
- Is there any way to stretch its' memoization across a block context instead of example context? ...or is that a horrid idea?
- Are there efficient ways to generate exceptionally large amounts of mock data that aren't likely to take 7+ seconds to load? I've seen vague references to Factory Girl but there's enough fighting on that note I don't know what to think in a current context.
Thank you for your time!