a minimalist's unit testing framework
This project is maintained by seancorfield and jaycfields
adding signal, removing noise
(expect [["/tmp/hello-world" "some data" :append true]
["/tmp/hello-world" "some data" :append true]]
(side-effects [spit]
(spit "/tmp/hello-world" "some data" :append true)
(spit "/tmp/hello-world" "some data" :append true)))
In the above example, you specify that spit is a side effect fn, and the 'side-effects macro will return a list of all calls made, with the arguments used in the call. The above example uses simple equality for verification.
(expect empty? (side-effects [spit] "spit never called"))The above example demonstrates how you can use non-equality to verify the data returned.
(expect ["/tmp/hello-world" "some data" :append true]
(in (side-effects [spit]
(spit "some other stuff" "xy")
(spit "/tmp/hello-world" "some data" :append true))))
Immediately above is an example of combining 'side-effects with 'in for a more concise test. Here we're testing that the expected data will exist somewhere within the list returned by 'side-effects
(expect (more-of [path data action {:keys [a c]}]
String path
#"some da" data
keyword? action
:b a
:d c)
(in (side-effects [spit]
(spit "/tmp/hello-world" "some data" :append {:a :b :c :d :e :f}))))
The above test is a bit much to swallow at first glance; however, it's actually very straightforward
once you've gotten used to the 'more-of syntax. In the above example the 'spit fn is called with
the args "/tmp/hello-world", "some data" :append {:a :b :c :d :e :f}. Using 'more-of,
we destructure those args, and expect them individually. The path arg is expected to be of type String.
The data arg is expected to be a string that matches the regex #"some da". The action is expected to be a 'keyword?. Finally, the options map is destructured to it's :a and :c values, and equality expected.