This post originated from an RSS feed registered with Ruby Buzz
by Jay Fields.
Original Post: Clojure: expectations & with-redefs
Feed Title: Jay Fields Thoughts
Feed URL: http://blog.jayfields.com/rss.xml
Feed Description: Thoughts on Software Development
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.