store/[org.clojure/clojure "1.8.0"] clj::clojure.core/with-redefs

Official Documentation

Add notes
Arities
==================================================
   [bindings & body]

Docstring
==================================================
  binding => var-symbol temp-value-expr

  Temporarily redefines Vars while executing the body.  The
  temp-value-exprs will be evaluated and each resulting value will
  replace in parallel the root value of its Var.  After the body is
  executed, the root values of all the Vars will be set back to their
  old values.  These temporary changes will be visible in all threads.
  Useful for mocking out functions during testing.

Source

(defmacro with-redefs
  "binding => var-symbol temp-value-expr

  Temporarily redefines Vars while executing the body.  The
  temp-value-exprs will be evaluated and each resulting value will
  replace in parallel the root value of its Var.  After the body is
  executed, the root values of all the Vars will be set back to their
  old values.  These temporary changes will be visible in all threads.
  Useful for mocking out functions during testing."
  {:added "1.3"}
  [bindings & body]
  `(with-redefs-fn ~(zipmap (map #(list `var %) (take-nth 2 bindings))
                            (take-nth 2 (next bindings)))
                    (fn [] ~@body)))

Example 1

Edit
(ns http)

(defn post [url]
  {:body "Hello world"})

(ns app
  (:require [clojure.test :refer [deftest is run-tests]]))

(deftest is-a-macro
  (with-redefs [http/post (fn [url] {:body "Goodbye world"})]
    (is (= {:body "Goodbye world"} (http/post "http://service.com/greet")))))

(run-tests) ;; test is passing

Example 2

Edit
;; be careful, with-redefs can permanently change a var if applied concurrently:

(defn ten [] 10)
;; => #'user/ten
(doall (pmap #(with-redefs [ten (fn [] %)] (ten)) (range 20 100)))
;; => (20 21 22 22 24 25 29 27 26 29 30 31 32 33 35 35 36 37 38 39 40 41 42 43 46 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 75 79 80 81 82 83 84 85 86 87 88 89 90 91 92 88 91 95 96 97 98 99)
(ten)
;; => 90

Example 3

Edit
;; redefine var
(def foo 1)
;; => #'user/foo
(with-redefs [foo 2]
  foo)
;; => 2

;; redefine private var
(ns first)
(def ^:private foo 1)
;; => #'first/foo

(ns second)
(with-redefs [first/foo 2]
  @#'first/foo)
;; => 2

;; @#' is the macros of (deref (var first/foo))
(with-redefs [first/foo 2]
  (deref (var first/foo)))
;; => 2

Example 4

Edit
[(type []) (class [])]
;; => [clojure.lang.PersistentVector clojure.lang.PersistentVector]

(with-redefs [type (constantly java.lang.String)
              class (constantly 10)]
  [(type []) (class [])])
;; => [java.lang.String 10]

Uses on crossclj