 
 ;; Binding map related
 
-(defn- unique-vars [fakes]
+(defn- #^:tested-private unique-vars [fakes]
   (distinct (map :lhs fakes)))
 
-(defn- binding-map-with-function-fakes [fakes]
+(defn- #^:tested-private binding-map-with-function-fakes [fakes]
   (letfn [(fn-that-implements-a-fake [function]
             (vary-meta function assoc :midje/faked-function true))
           (make-faker [var]

;;; Binding


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

(defmulti ^:private call-handled-by-fake? (fn [function-var actual-args fake] (:type fake)))

(defmethod call-handled-by-fake? :not-called [function-var actual-args fake]
  (var-handled-by-fake? function-var fake))

(defmethod call-handled-by-fake? :default [function-var actual-args fake]
  (and (var-handled-by-fake? function-var fake)
       (= (count actual-args) (count (:arg-matchers fake)))
       (extended-list-= actual-args (:arg-matchers fake))))

(defn usable-default-function? [fake]
  (and (bound? (:lhs fake))
       (let [stashed-value (var-get (:lhs fake))
             unfinished-fun (:midje/unfinished-fun (meta (:lhs fake)))]
         (and (extended-fn? stashed-value)
              (or (nil? unfinished-fun)
                  (not= unfinished-fun stashed-value))))))


(def ^:dynamic ^:private *call-action-count* (atom 0))
(defmacro ^:private counting-nested-calls-calls [& forms]
  `(try
     (swap! *call-action-count* inc)
     ~@forms
     (finally (swap! *call-action-count* dec))))

(defn- best-call-action [function-var actual-args fakes]
  (when (= 2 @*call-action-count*)
    (throw (user-error "You seem to have created a prerequisite for"
             (str (pr-str function-var) " that interferes with that function's use in Midje's")
             (str "own code. To fix, define a function of your own that uses "
               (or (:name (meta function-var)) function-var) ", then")
             "describe that function in a provided clause. For example, instead of this:"
             "  (provided (every? even? ..xs..) => true)"
             "do this:"
             "  (def all-even? (partial every? even?))"
             "  ;; ..."
             "  (provided (all-even? ..xs..) => true)")))
  (if-let [found (find-first (partial call-handled-by-fake? function-var actual-args)
                             fakes)]
    found
    (let [possible-fakes (filter (partial var-handled-by-fake? function-var) fakes)]
      (cond (empty? possible-fakes)
        nil
  
        ;; For finding a default, any possible fake is as good as any other
        (not (usable-default-function? (first possible-fakes)))
        nil
  
        :else (:value-at-time-of-faking (first possible-fakes))))))

(defn- call-faker
  "This is the function that handles all mocked calls." 

  (or (first-named? form "fake") 
      (first-named? form "data-fake")))

;;; Creation

(defn make-fake-map
