Clojure: expectations & with-redefs

In general, when I'm writing tests, the pure functions end up as bare expects and the impure functions end up as scenarios. The following contrived namespace keeps a list of users and allows you to get the full name of each user.



The tests for this namespace would often look something like the following code:



It feels natural to put the with-redefs in a scenario, since scenarios also support (and often make use of) stubbing, localize-state, & freeze-time. However, there's really no reason that you need to use a scenario if you're simply looking to redef a var.



The following test provides the same level of functionality verification, without needing to use expectations.scenarios:




scenarios are great, but these days I try to keep things simple with bare expectations whenever possible.
© Jay Fields - www.jayfields.com
 •  0 comments  •  flag
Share on Twitter
Published on June 05, 2012 06:00
No comments have been added yet.