Fork me on GitHub
#testing
<
2022-04-19
>
mauricio.szabo14:04:20

I do like the Midge-like DSL, but it's so unpredictable that I prefer not to use it. In fact, http://gitlab.com/mauricioszabo/check (my testing library) implements a DSL-like approach, but with a single macro that expects 3 args: actual, matcher, and expected. It also implements, with the same macro, a clojure-test based approach, so I can use it as (check (+ 1 2) => 3) or (check (=> 3 (+ 1 2))). Some people prefer the first, some prefer the second. I built this library for some reasons. First, because I wanted to use a midje-like library but most did not support ClojureScript that well at the time; second, because I wanted better errors (so there's even a defmatcher if none of the current matchers work); and third, because I needed async testing in ClojureScript, and most libraries get this wrong in some way or other...

👍 1
mauricio.szabo13:04:21

Midje is great, the trouble is to get the macros and the syntax in the right positions. For example, this code:

(facts "Getting a mixer."
       (pos? (count (mixer-info))) => true
       (keys (info (first (mixer-info)))) => [:description :name :vendor :version]
       (info (first (mixer-info)) :vendor) => "ALSA ()"
       (mixer) => (mixer nil)
       (mixer (first (filter #(includes? (info % :name) "[default]") (mixer-info)))) => (mixer))
It works, but if you add a let between facts and the assertions, it sometimes broke with strange errors

👍 1
mauricio.szabo13:04:52

But only sometimes, not always, and the error was like "midje did not understand something you wrote" which was not helpful at all

mauricio.szabo13:04:57

(BTW, that example translates almost line-by-line to my library check - you just need to replace factsfor clojure.test/testing, and wrap every assert (the code, the arrow, and expected result) into check, like (check (pos? (count (mixer-info))) => true) for example)

👍 1