Use Tap For Better Test Data Setup
I often use RSpec's let
statement to set up some test data.
Often times, realistic test data requires setting up peripheral data as well.
This can get hard to read as the subject of the let
gets obscured. It is also clumsy that we have to end with returning the order
. This can be cleaned up with the use of #tap
.
The block notation and indentation make it clear that the order
is what is getting created. Meanwhile, the interior of the block gives us a designated area to do what we need to with the newly-created order
instance.
Last updated