Fork me on GitHub
#testing
<
2017-03-18
>
facundo16:03:03

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)

nberger18:03:58

@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 hand

nberger18:03:05

c.t/report is just for reporting, not for assertions

nberger18:03:47

And nice to see you around btw :)

facundo18:03:50

thanks for the answer @nberger ! that code was useful, but I figure I wasn’t accurate when I said assertion functions

facundo18:03:33

I actually want to create a function to use instead of is rather that something to call inside is

facundo18:03:29

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”}))))

facundo18:03:23

the expect function checks the response of the request against the parameters given (:status, :body, etc)

facundo18:03:54

I already implemented expect wrapping calls to is, which works well enough

facundo18:03:37

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