Midje checkables can have functions on the right-hand side. Like this:
(fact (f 33) => even?)
The function is called with the result of the left-hand side. To distinguish such uses from other ones, we say that
even? is a checker in the above checkable.
Often, checkers will take arguments that describe the expected value. These are built with function-generating functions:
user=> (defn each-element-is-one-of [expected-elements] (fn [actual] (every? (set expected-elements) actual))) user=> (fact [1 2] => (each-element-is-one-of [1 2 3 4])) true
Midje predefines some checkers that are particularly useful on the right-hand side. (Checkers are also used to match prerequisite arguments in top-down TDD, but that's not covered here.) The rest of this page describes the simpler predefined checkers.
truthy or TRUTHY
(fact (f) => truthy)
truthy when you don't care about a particular truth value, just that it's neither
falsey or FALSEY
(fact (f) => falsey)
falsey when you care that the value is either
false, but don't care which.
anything or irrelevant
(fact (f) => anything)
anything is used for "don't care" arguments in prerequisites but you could also use it to say that you make no assertions about the result of a function.
irrelevant is a synonym.
(exactly fn )
(fact (make-function-with-goedel-number 3) => (exactly odd?))
exactly when you want to talk about a particular function as a value, rather than applying it as a checker.
(roughly number range )
True if the actual value is within
range is not given, it's taken to be 1/1000th of
(throws class message predicate )
(fact (explosion) => (throws Exception))
(fact (explosion) => (throws Exception "boom!"))
(fact (explosion) => (throws trace-of-c4?))
(fact (explosion) => (throws #"boom" #"bang" #"smash"))
throws when you expect the function to raise an exception.
If there is more than one argument, all of them must check successfully against the message. None of the arguments are required. There can be at most one class argument, but there can be more than one message or predicate argument.
Last edited by Brian Marick,