Skip to content
Brian Marick edited this page May 21, 2015 · 27 revisions

The basic lein midje options were covered in lein-midje basics. They are:

% lein midje                        # Check facts in source and test namespaces
% lein midje proj.ns-1 proj.ns-2    # Check facts in selected namespaces
% lein midje proj.subproj.*         # Check facts in a subtree of namespaces

% lein midje :autotest              # Check all facts once; recheck changed namespaces.

lein midje has further options. Options have Clojure keyword syntax. (Thus, :autotest is an option.) When options take arguments, they are all the following tokens, up to the next option or the end of the arguments.

Options

:config

The arguments are pathnames that override Midje's default configuration files. Here's an example:

% lein midje :config /Users/marick/alternate-config configs/integration

Notes:

  • Pathnames are relative to the root of the project directory.
  • Config files are read in left to right order.
  • The default config files are not read when the :config option is given.

As a result of the last, :config with no arguments means that Midje reads no config files.

:autotest

Autotest works in terms of directories full of Clojure files, not namespaces. You can limit which directories it considers by giving it specific directories:

% lein midje :autotest test/midje/util src/midje/util

Notes:

  • Pathnames are relative to the project's root.
  • Changes do not propagate "through" unmentioned directories. See the autotest page for an explanation and an example.
  • There is no way to point :autotest at individual files.

:filter

Midje facts have metadata that allows you to tag them with arbitrary information. Here are three examples:

(fact "this is an ordinary test" ...)
(fact "this is a core test" :core ...)
(fact "this is a slow test" :slow ...)
(fact "this is a slow core test" :core :slow ...)

The :filter option allows you to restrict which facts in the already-selected namespaces are run. For example, to check the core facts in all the namespaces, you'd use:

% lein midje :filter core

To run the core tests in only the utility directory, you'd use:

% lein midje utility.* :filter core

Filter terms can be negated by preceding them with -. Here is how you'd autotest all the facts that aren't marked as slow:

% lein midje :autotest :filter -slow

When there is more than one filter term, facts that match any of them are run. For example, the following runs all the fast (not :slow) tests, but runs core tests even if they're slow.

% lein midje :filters -slow core

Note that :filters is a synonym for :filter.

This "match any" interpretation of :filter can be confusing in cases like this:

(fact :agent
  :agent => :failed)

(fact :integration
  :integration => :failed)

(fact
  :passes => truthy)

Suppose you want to run only the fact that's neither :agent nor :integration. The temptation is to do it like this:

% lein midje :filter -integration -agent 

That, however, still runs all three of the tests. The first is run because it's not :agent, the second because it's not :integration, and the third because it's not either. There's no way to get the behavior you want on the command line. For this, and for more complicated situations, use configuration files. Put the following in a file like fast.config:

(change-defaults :fact-filter #(and (not (:agent %))
                                    (not (:integration %))))

Then run lein midje like this:

$ lein midje :config fast.config
Clone this wiki locally