Last active
August 29, 2015 14:17
-
-
Save jjl/266e4fd88846ab8674f4 to your computer and use it in GitHub Desktop.
Midje intermingled tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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