Skip to content

Using midje at the command line

marick edited this page Feb 15, 2013 · 3 revisions

First install lein-midje in your .lein/profiles.clj file:

{:user {:plugins [[lein-midje "3.0.0"]]}}

To check everything:

% lein midje

That checks all facts and clojure.test tests in your project's :test-paths and :source-paths. (Midje users sometimes add facts to their source as documentation.) You can also name one or more specific namespaces:

% lein behaviors.t-line-number-reporting midje.checkers.t-collection

You can also use * to abbreviate multiple namespaces:

```bash` % lein midje midje.emission.*


Note that `*` names a whole namespace subtree. That is, the previous command will check both `midje.emission.t-api` and `midje.emission.plugins.t-default`. 

`lein midje` shows output like this:

FAIL "a '`fact' that's not true" at (core.clj:7) ;; FAIL is normally highlighted in red. Expected: 5 Actual: 4

Output from clojure.test tests:

FAIL in (a-test-that-fails) (core.clj:9) expected: (= (+ 2 2) 5) actual: (not (= 4 5))

1 failures, 0 errors. ;; Highlighted in red to mark failure

Midje summary: FAILURE: 1 claim was not confirmed. (But 1 was.) ;; Highlighted in red. Subprocess failed $ echo $? 2


Notes:
* The `clojure.test` output only appears if any `deftests` were run. The Midje and `clojure.test` outputs are never mixed together, even if tests and facts appear in the same namespace.

* [[Colorizing]] can be changed. 

* The exit status is the number of failures (whether from `clojure.test` or Midje), up to a maximum of 255. As a result, scripts on Unix-like systems can check for success or failure in the normal way.

## 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:

```bash
% 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. For example, suppose that the test namespace midje.util.t-final depends on source namespace midje.emission.api, which itself depends on source namespace midje.util.ecosystem. A change to midje.util.ecosystem would not cause the facts in midje.util.t-final to be rechecked because src/midje/emission is not being watched for changes.
  • There is no way to point :autotest at individual files.

Other features

See lein help midje for a concise description of options. If you want to check only some facts, see using metadata to filter facts. If you're interested in customizing Midje, see configuration files.

Clone this wiki locally