-
Notifications
You must be signed in to change notification settings - Fork 129
Lein midje
This covers version 3.x+ of lein midje
, which only runs under Leiningen 2 and Midje 1.5.X+. For information on older versions, see the lein-midje project page or use lein help midje
.
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.
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 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. Consider the picture below, where the shaded directories have been mentioned to autotest:
File
t_a.clj
testsa.clj
, andt_b.clj
testsb.clj
. It also happens thatb.clj
requiresa.clj
. Now consider what happens whena.clj
changes. It's reloaded.t_a.clj
is reloaded because it depends ona.clj
.b.clj
is not reloaded because we didn't ask autotest to watch it. Further,t_b.clj
is also not reloaded, even though autotest is watching it, because autotest doesn't know of the indirect dependency throughb.clj
. -
There is no way to point
:autotest
at individual files.
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
.