Hello Alexander, Marc,
Ah, now I get this. Thank you for your responses!
вторник, 21 июля 2015 г., 17:54:42 UTC+3 пользователь Yuri Govorushchenko
написал:
>
> The problem I'm trying to solve is how to stub a variable (e.g. a function
> from a third-party lib) in tests so that the stubbing occu
Hi Yuri,
You need to call .setDynamic before the access to the var is compiled. In
your test, the call to .setDynamic is invoked when the function is called,
which is after the function has been compiled. So when compiler sees the
read of static-var the var is still static, and it can emit a read
Hello Yuri,
You probably need something like with-redefs[1] to do mocking. Setting a
var to dynamic at runtime will have impact only on code that was *compiled*
after
doing that. See the excerpt from Daniel's talk about this behavior[2].
[1]
http://conj.io/store/v1/org.clojure/clojure/1.7.0/c
Sorry, didn't link to the exact time. The correct link
is: https://youtu.be/8NUI07y1SlQ?t=217
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated
Thank you for a reply, I totally agree with you on dependency injection.
Though I'm exercising in writing a mocking framework and thought it would
be an interesting feature to implement a thread-safe mocking of an implicit
dependency.
среда, 22 июля 2015 г., 5:03:36 UTC+3 пользователь Surgo нап
Not that it's the answer you're looking for, but usually this is when you
rewrite the code you're testing to use dependency injection (ie, take the
var of interest as an argument instead of a global or in its lexical
environment).
-- Morgon
On Tuesday, July 21, 2015 at 10:54:42 AM UTC-4, Yuri
The problem I'm trying to solve is how to stub a variable (e.g. a function
from a third-party lib) in tests so that the stubbing occurs only in the
current thread with other threads continuing using var's root value. It's
important because unit tests may be run in parallel. Without thread-local