Skip to content

Instantly share code, notes, and snippets.

@AlexBaranosky
Created January 15, 2012 05:36
Show Gist options
  • Save AlexBaranosky/1614509 to your computer and use it in GitHub Desktop.
Save AlexBaranosky/1614509 to your computer and use it in GitHub Desktop.
Midje `formula`
;; This first swipe at generative-style testing in Midje was super easy:
;; first a use of it
(defn make-string []
(rand-nth ["a" "b" "c" "d" "e" "f" "g" "i"]))
(formula [a (make-string) b (make-string)]
(str a b) => #(.startsWith % a))
;; How its defined
(def ^:dynamic *num-generations* 100)
(defmacro formula [bindings & body]
(macro-for [_ (range *num-generations*)]
`(let ~bindings
(midje.sweet/fact
~@body))))
;; NOTES:
;; * just borrow some generator functions from test.generative, and voila
;; a stripped down generative test framework.
;; * this version makes a fact for every generation which would quickly
;; make the fact count in the report meaningless.
;; * doc-strings can be added later.
;; QUESTIONS:
;; * how can we make the reporting of these really nice?
;; * is this it? There has to be more to this kind of thing than simply
;; generating 100 of each formula. What do you think?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment