(ns leiningen.hooks.mock
  "Replace all vars in all namespaces  with their :mock metadata, if present."
  (:use [robert.hooke :only [add-hook]]
        [leiningen.compile :only [eval-in-project]]))

(def mockery
  `(fn [f# & args#]
     (doseq [n# (all-ns)
             [_# v#] (ns-publics n#)
             :when (:mock (meta v#))]
       (alter-var-root v# (fn [f# v#] (with-meta (:mock (meta v#))
                                       (assoc (dissoc (meta v#) :mock)
                                         :leiningen.mock/original v#))) v#))
     (apply f# args#)))

(defn add-mock-form [eval-in-project project form & [handler]]
  (let [form `(do (require '~'clojure.test)
                  (require '~'robert.hooke)
                  (#'robert.hooke/add-hook #'~'clojure.test/run-tests ~mockery)
                  ~form)]
    (eval-in-project project form handler)))

(add-hook #'eval-in-project add-mock-form)

Generated by Phil Hagelberg using scpaste at Mon Sep 27 20:55:42 2010. PDT. (raw)