At work, we’re deciding on our test-writing style: let/let! blocks like let(:arg) { 5 } vs. instance variables defined in a setup method like @arg = 5.
- I’ve found no advantage to
let; but I have experienced disadvantages. - I’ve found no disadvantages to instance variables.
And so, 👍 for instance variables.
I’ve written many specs and have read the rspec docs, betterspecs.org many times.
I don’t use let/let! because
- the purported advantage of lazy evaluation is never actually realized. I’m most always running all the tests in a file, and so there’s no time efficiency gain;
- the API [
letandlet!] and their magic increase the code’s complexity and so must be balanced out by some other advantage; - Let introduces magic and apparently nondeterministic behavior which has broken my tests, and I’ve only been able to fix by converting to easy-to-understand
@-variable instantiations. -
Let has the problem of introducing non-ruby syntax — something that looks like an automatic variable isn’t one anymore.
So for me, let is fixing a problem I don’t have, and in doing so, introduces new problems.
Leave a reply to Robb Cancel reply