-
Notifications
You must be signed in to change notification settings - Fork 129
Folded prerequisites
marick edited this page Feb 20, 2013
·
8 revisions
Checkers can be used as both expected values of assertions and also in the argument lists of prerequisites:
(fact
(f 1) => truthy ; as expected value of assertion
(provided
(g truthy) => 3)) ; as argument of prerequisite
Some checkers, like roughly
, are actually functions that generate checking functions:
(fact
(f 1) => (exactly odd?)
(provided
(g (roughly 3.0)) => 800.0))
How does Midje know that (g (roughly ...))
is a checker, not a prerequisite to be folded? It is defined specially:
(defchecker roughly
"With two arguments, accepts a value within delta of the
expected value. With one argument, the delta is 1/1000th
of the expected value."
([expected delta]
(checker [actual] ; <<= Checker tags the generated function as a checker.
(and (>= expected (- actual delta))
(<= expected (+ actual delta)))))
([expected]
(roughly expected (* 0.001 expected))))
If you define your own function-generating checkers, they should use similar macros. See Checkers within prerequisites.