Jay Fields
Posts: 765
Nickname: jayfields
Registered: Sep, 2006
|
Jay Fields is a software developer for ThoughtWorks
|
|
|
|
Clojure: expectations & with-redefs
|
Posted: Jun 5, 2012 6:51 AM
|
|
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.
Read: Clojure: expectations & with-redefs
|
|