Skip to content
marick edited this page Apr 27, 2012 · 28 revisions

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 or 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 neither nil nor false.

  • falsey or FALSEY

    (fact (f) => falsey) or (provided (f falsey) => 3)

    Use falsey when you care that the value is either nil or false, but don't care which.

  • anything or irrelevant

    (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 ± the range. If range is not given, it's taken to be 1/1000th of number.

  • (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 one message or predicate argument. The class argument names a class. The message argument can be either a string or a regular expression.

Clone this wiki locally