Readplace

with-redefs - clojure.core

ClojureDocs 2 min read
View original
Summary (TL;DR)
with-redefs temporarily changes the root value of Vars during execution of body, restoring old values after. Changes are visible in all threads. Useful for mocking in tests. Example: (with-redefs [foo 2] foo) returns 2. Be careful with parallelism; concurrent use can permanently alter a Var. Does not work on macros or inlined functions. Redefs happen in parallel, so one redef cannot reference another's new value.