Skip to content

Basic repl tools

marick edited this page Feb 7, 2013 · 2 revisions
Clone this wiki locally

Although you could use Midje without Leiningen, I don't recommend it. That said, the easiest way to begin learning Midje is with the repl tools. In some project that includes Midje in its project.clj dependencies, type this:

% lein repl
;;; Leiningen startup text appears here ;;;

user=> (use 'midje.repl)
Run `(doc midje)` for Midje usage.
Run `(doc midje-repl)` for descriptions of Midje repl functions.

Notice that Midje provides summary documentation. For example, (doc midje) is an index to several Midje topics, such as (doc checkers), which reminds you of the names of all the different Midje checkers.

There are several ways to use the repl. Here they are in descending order of convenience (in my opinion): (Note: only the last of these works prior to Midje 1.5.)

  • Type (autotest) at the repl prompt. That will load all the facts in the test and source directories. (Some Midje users add facts to their source as documentation, so Midje tools will usually work with both source and test directories.) Thereafter, it watches for changes in the files. When a change happens, the changed file is reloaded, and so are all files that depend on it (either directly or indirectly). As a result, a change to the source will cause facts to be rechecked.

    You can continue to work at the repl. If you're also saving files, autotest could become annoying. In that case, you can pause it during your repl work, and resume it after:

     ;;; autotest output here, so the prompt doesn't appear
     (autotest :pause)
     user=> ;;; work, work, work,
     user=> (autotest :resume)

    (When you resume autotest, it will notice all the files that have changed since you paused it.)


  • Edit files and reload them manually. Midje provides a shorthand for that:

    user> (load-facts)

    The first time you type that, it will load all the test files and all the source files.

    When you type it again, both the test and source namespaces are "forgotten", so that they are reloaded again. The effect is that you can change a source file, type (load-facts) again, and have the facts checked against the changed code. There's no need to require the changed source in the repl.


  • Send Midje facts from your editor to the repl, whether by cutting and pasting or by using your editor's tooling. (Although I list this as least convenient, it can actually be pretty convenient if your editor's tooling is sufficient. See Midje mode if you're an Emacs user.)

Something went wrong with that request. Please try again.