Re: Seeking advice on a safe way to mock/stub fns

2013-03-27 Thread Shantanu Kumar
On Wednesday, 27 March 2013 08:06:30 UTC+5:30, Leif wrote: Hi, Shantanu. Thanks for the suggestions. A couple thoughts: 1. Many times, I seem to stub or mock things that are scattered here and there in the code, like things that send email or log metrics, etc. so they are not really

Re: Seeking advice on a safe way to mock/stub fns

2013-03-27 Thread Shantanu Kumar
Sorry, in the last illustration, the (binding [*deps* deps] ...) cannot be useful for Compojure route handlers because dynamic vars are bound at a thread-local level; you will probably have to `alter-var-root` it to some var and have the handlers use that static var instead. In the code I write

Re: Seeking advice on a safe way to mock/stub fns

2013-03-27 Thread John D. Hume
On Mar 27, 2013 1:56 AM, Shantanu Kumar kumar.shant...@gmail.com wrote: Sorry, in the last illustration, the (binding [*deps* deps] ...) cannot be useful for Compojure route handlers because dynamic vars are bound at a thread-local level; you will probably have to `alter-var-root` it to some var

Re: Seeking advice on a safe way to mock/stub fns

2013-03-27 Thread Shantanu Kumar
On Wednesday, 27 March 2013 17:54:01 UTC+5:30, John Hume wrote: On Mar 27, 2013 1:56 AM, Shantanu Kumar kumar.s...@gmail.comjavascript: wrote: Sorry, in the last illustration, the (binding [*deps* deps] ...) cannot be useful for Compojure route handlers because dynamic vars are bound

Re: Seeking advice on a safe way to mock/stub fns

2013-03-26 Thread Leif
Hi, Allen. My own version of with-redefs? That *sounds* kind of hard. Could you keep an atom with the original bound value (the first one my-with-redefs sees, anyway) and then always roll back to that value? Something like that? Thanks, Leif On Monday, March 25, 2013 1:58:53 AM UTC-4,

Re: Seeking advice on a safe way to mock/stub fns

2013-03-26 Thread Leif
Hi, Shantanu. Thanks for the suggestions. A couple thoughts: 1. Many times, I seem to stub or mock things that are scattered here and there in the code, like things that send email or log metrics, etc. so they are not really isolated (or isolatable??), but I still want to test that they get

Re: Seeking advice on a safe way to mock/stub fns

2013-03-25 Thread Shantanu Kumar
On Monday, 25 March 2013 06:45:32 UTC+5:30, Leif wrote: Hello, fellow Clojurians. One problem I've run into when stubbing fns is that with-redefs doesn't play well with concurrency. E.g. http://clojuredocs.org/clojure_core/clojure.core/with-redefs#example_994 The problem arises

Seeking advice on a safe way to mock/stub fns

2013-03-24 Thread Leif
Hello, fellow Clojurians. One problem I've run into when stubbing fns is that with-redefs doesn't play well with concurrency. E.g. http://clojuredocs.org/clojure_core/clojure.core/with-redefs#example_994 The problem arises because, quoting with-redef's docstring, These temporary changes

Re: Seeking advice on a safe way to mock/stub fns

2013-03-24 Thread Allen Rohner
I've also run into the problem. You could write your own version of with-redefs (it's not that hard). In your case, it sounds like you're not running tests in parallel in the same process, so could you work around it by waiting for your app to finish initializing before running tests? Allen