                                                    with-altered-roots]]
         [midje.error-handling.exceptions :only [user-error]]
         [midje.internal-ideas.wrapping :only [with-wrapping-target]]
-        [midje.ideas.arrow-symbols])
+        [midje.ideas.arrow-symbols]
+        [clojure.tools.macro :only [macrolet]])
   (:require [clojure.zip :as zip])
   (:import midje.ideas.metaconstants.Metaconstant))
 

(defn tag-as-background-fake [fake]
  (concat fake `(:background :background :times (~'range 0))))

;;; Binding


(letfn [(var-handled-by-fake? [function-var fake]
          (= function-var (:lhs fake)))]

    
          :else (:value-at-time-of-faking (first possible-fakes)))))))

(defn- #^:tested-private call-faker
  "This is the function that handles all mocked calls."
  [function-var actual-args fakes]
  (macrolet [(counting-nested-calls [& forms]
               `(try
                  (swap! *call-action-count* inc)
                  ~@forms
                  (finally (swap! *call-action-count* dec))))]

    (let [action (counting-nested-calls (best-call-action function-var actual-args fakes))]
      (cond (nil? action)
        (clojure.test/report {:type :mock-argument-match-failure
                              :lhs function-var
                              :actual actual-args
                              :position (:position (first fakes))})

        (extended-fn? action)
        (apply action actual-args)

        :else (do
                (swap! (action :count-atom ) inc)
                ((action :result-supplier )))))))

;; Binding map related

