Hi! does anyone know where to find a good example on how to use clojure.test/report
to build custom assertion functions? (I understand that’s the way to go rather than wrapping clojure.test/is
)
@facundo: the way to do that is by defining new methods of the assert-expr
multimethod. From the clojure.test ns dictating:
EXTENDING TEST-IS (ADVANCED)
You can extend the behavior of the \"is\" macro by defining new
methods for the \"assert-expr\" multimethod. These methods are
called during expansion of the \"is\" macro, so they should return
quoted forms to be evaluated.
I don't have an example at handc.t/report is just for reporting, not for assertions
And nice to see you around btw :)
Here you can find some examples from clojure.test itself: https://github.com/clojure/clojure/blob/master/src/clj/clojure/test.clj#L491
thanks for the answer @nberger ! that code was useful, but I figure I wasn’t accurate when I said assertion functions
I actually want to create a function to use instead of is
rather that something to call inside is
I already have a working version of what I want, but wrapping is
calls. It goes something like this:
(deftest application-crud
(testing "create a new app"
(-> (POST "/api/v1/management/applications" {:name "my-app"})
(expect :status 201
:body {:name “my-app”}))))
the expect
function checks the response of the request against the parameters given (:status, :body, etc)
I already implemented expect wrapping calls to is
, which works well enough
the one thing that I’m loosing is the line numbers, which point to the expect definition rather than the failing test. I imagine I could make a macro or something to preserve the line numbers