Fork me on GitHub
#pedestal
<
2017-07-12
>
jimmy16:07:48

hi guys, can we do with-redefs with response-for to unit test routes in Clojure? I tried but the function doesn’t seem seem to be redefined.

ddeaguiar17:07:58

@nxqd I generally avoid with-redefs in tests as it changes the root value of a Var. One consequence of this is that it makes running tests in parallel impossible. I prefer using dynamic vars with binding. I’m guessing you are trying to stub out a function call. In that case consider your tests as feedback indicating that there’s an opportunity to explicitly introduce some abstraction and associated dependency.

ddeaguiar17:07:30

That being said, I don’t see why with-redefs would not work with response-for as long as you are targeting an application-specific var. The interceptor chain is still being executed.