Fork me on GitHub
#clojure-uk
<
2020-02-22
>
dharrigan08:02:35

Good Morning!

folcon11:02:53

I’ve been looking at irritations with testing recently and wondering if there’s a decent out of the box solution for this. On test failure, you get something like this:

Error: Assert failed: (<= -4 (:morale kingdom) 4)
Whereas I’d like to know the value of (:morale kingdom), as the automatic next step is pulling out that value… (This is in figwheel, though there’s no reason I couldn’t be writing this in clojure if there’s better tooling there…) Anyone have any good suggestions?

dominicm12:02:46

Generally, you write a function

dominicm12:02:59

Where that argument is the first argument

folcon12:02:29

Sorry @dominicm, what do you mean? Should I be wrapping (<= -4 (:morale kingdom) 4) as a function?

dominicm12:02:06

Yeah. So you'd have something like:

(defn valid-morale?
  [morale]
  (<= -4 morale 4))
Then
(is (valid-morale? (:morale kingdom)))
If it fails, you will get a useful message.

folcon12:02:41

Let me try that =)…

folcon13:02:32

Ah, I get it, I shouldn’t be using assert, just is

folcon13:02:46

That’s exactly the behaviour I wanted, thanks!

dominicm13:02:00

There's also the part where clojure test doesn't do a good job of making messages unless a certain argument is the constant.

dominicm13:02:15

Although it's strongly possible this wasn't the case here.

folcon13:02:03

yea, that wasn’t the issue =)…