Skip to content

Instantly share code, notes, and snippets.

@jjl
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjl/266e4fd88846ab8674f4 to your computer and use it in GitHub Desktop.
Save jjl/266e4fd88846ab8674f4 to your computer and use it in GitHub Desktop.
Midje intermingled tests
(ns my.namespace
(:require [util :refer [dev-prelude]]))
; in dev, import midje
; in live, strip out any code that uses midje
(dev-prelude)
(def always (constantly true))
; tests!
(facts "always"
(always) => true))
(defmacro safely [& stmts]
`(try ~@stmts
(catch Exception ~'e)))
(defn- are-we-in-dev? []
(let [lein-home (System/getenv "LEIN_HOME")
lein-no-dev (System/getenv "LEIN_NO_DEV")]
(and lein-home
(nil? lein-no-dev))))
(defmacro in-dev [& exprs]
(when (are-we-in-dev?)
`(do ~@exprs)))
(defmacro in-live [& exprs]
(when-not (are-we-in-dev?)
`(do ~@exprs)))
(defn ^:Private nil-macro [name]
`(defmacro ~name [& ~'exprs] nil))
(defmacro ^:Private nil-macros [& names]
`(do ~@(map nil-macro names)))
(defmacro dev-prelude []
`(do
(safely
(in-dev (use 'midje.sweet))
(in-live ~@(nil-macros facts fact unfinished tabular background)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment