Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
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)
truthywhen you don't care about a particular truth value, just that it's neither
falsey or FALSEY
(fact (f) => falsey)
falseywhen you care that the value is either
false, but don't care which.
anything or irrelevant
(fact (f) => anything)
anythingis 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.
irrelevantis a synonym.
(exactly fn )
(fact (make-function-with-goedel-number 3) => (exactly odd?))
exactlywhen 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
rangeis not given, it's taken to be 1/1000th of
- (throws class message predicate )
;; check exception class (fact (explosion) => (throws Exception)) ;; check exception class and message (fact (explosion) => (throws Exception "boom!")) ;; check exception satisfies predicate (fact (explosion) => (throws trace-of-c4?)) ;; check exception class and that it satisfies predicate (fact (explosion) => (throws ExceptionInfo trace-of-c4?)) ;; check with multiple predicates (fact (explosion) => (throws #"boom" #"bang" #"smash"))
throws when you expect the function to raise an exception.
- The class argument names a class.
- The message argument can be either a string or a regular expression. In the latter case, the rules of extended equality apply.
- The predicate is applied to the exception object to return either a truthy or falsey value.
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.