RSpec Stubs with no_args
We’ve been getting pretty particular about our stub/mock expectations at work. A few months ago I would been perfectly happy with:
I didn’t worry about specifying that I didn’t pass any arguments to the constructor. After it was pointed out that the stub didn’t really fully specify its’ expectations I changed to this style:
Then a colleague pointed out a nice bit of syntactic sugar. You can simply specify a no_args matcher if no arguments are passed in:
A more complete stub with better readability. Reminds me of how I fell in love with RSpec the first time I saw it back in 2006.