-
Notifications
You must be signed in to change notification settings - Fork 128
Checkers
Midje facts can have functions on the right-hand side of assertions. Like this:
(fact (f 33) => even?)
The function is called with the result of the left-hand side.
The rest of this page describes the simpler predefined checkers. See also checkers for collections and strings.
-
truthy
(fact (f) => truthy)
or(provided (f truthy) => 3)
Use
truthy
when you don't care about a particular truth value, just that it's neithernil
norfalse
. -
falsey
(fact (f) => falsey)
or(provided (f falsey) => 3)
Use
falsey
when you care that the value is eithernil
orfalse
, but don't care which. -
anything
(fact (f) => anything)
or(provided (f anything) => 3)
anything
is usually 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 (function-generator 3) => (exactly odd?)
or(provided (f (exactly odd?)) => 3)
Use
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
number
± therange
. Ifrange
is not given, it's taken to be 1/1000th ofnumber
.
-
(throws class message predicate )
(fact (explosion) => (throws Exception))
(fact (explosion) => (throws Exception "boom!"))
(fact (explosion) => (throws trace-of-c4?))
(fact (explosion) => (throws #"boo"))
Use
throws
when you expect the function to raise an exception. All of the arguments are optional. You can have more than onemessage
orpredicate
argument. Theclass
argument names a class. Themessage
argument can be either a string or a regular expression.