Skip to content

Commit

Permalink
[Issue #82] formula can now take an optional docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBaranosky committed Feb 19, 2012
1 parent 823a323 commit 6b91789
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
21 changes: 12 additions & 9 deletions src/midje/ideas/formulas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

(def #^:dynamic *num-generations* 100)

(defmacro formula [bindings & body]
`(do
(macro-for [_# (range (dec *num-generations*))]
(defmacro formula [docstring? & bindings+body]
(let [[docstring? bindings body] (if (string? docstring?)
[docstring? (first bindings+body) (rest bindings+body)]
[nil docstring? bindings+body])]
`(do
(macro-for [_# (range (dec *num-generations*))]
(let ~bindings
(midje.sweet/fact ~docstring?
~@body :formula :formula-in-progress )))

(let ~bindings
(midje.sweet/fact
~@body :formula :formula-in-progress )))

(let ~bindings
(midje.sweet/fact
~@body :formula :formula-conclude ))))
(midje.sweet/fact ~docstring?
~@body :formula :formula-conclude )))))
11 changes: 8 additions & 3 deletions test/midje/t_sweet.clj
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,19 @@
(provided
(a) =throws=> (IllegalArgumentException. "blammo")))


;; failed formulas report once per formula regardless how many generations were run
(after-silently
(formula [a "y"]
(formula "some description" [a "y"]
a => :foo))
(fact @reported => (one-of (contains {:type :formula-fail
:first-failure (contains {:type :mock-expected-result-failure})})))
:first-failure (contains {:type :mock-expected-result-failure
:description "some description"})})))

(defn make-string []
(rand-nth ["a" "b" "c" "d" "e" "f" "g" "i"]))

(formula [a (make-string) b (make-string)]
(formula
"can now use simple generative-style formulas"
[a (make-string) b (make-string)]
(str a b) => (has-prefix a))

0 comments on commit 6b91789

Please sign in to comment.