Skip to content

Configuration files

Laverne Schrock edited this page Apr 2, 2019 · 8 revisions

On startup, Midje loads ${HOME}/.midje.clj and ./.midje.clj (in that order). You can change configuration files with lein-midje:

% lein midje :config config-file-1 config-file-2

The two given configuration files are used instead of the defaults. They're loaded in left-to-right order. Because :config makes Midje forget the default files, you can tell it to load no configuration files at all like this:

% lein midje :config

Changing the configuration

A configuration file is loaded within the midje.config namespace. That namespace's change-defaults function overrides Midje's defaults. Here, for example, is how you'd change Midje's verbosity:

(change-defaults :print-level :print-namespaces)

If you want Midje to behave differently when run in the repl or via lein midje, use running-in-repl?

(when-not (running-in-repl?)
  (change-defaults :print-level :print-namespaces))

You can temporarily change the configuration like this:

(midje.config/with-augmented-config {:check-after-creation false}
  (load-facts :all))

Configuration options

  • :print-level <keyword>

    Change the verbosity of Midje output. The default is :print-normally. See print levels for a list.

  • :emitter <namespace name or string>

    The "emitter" formats Midje output. The default emitter is 'midje.emission.plugins.default. That's currently the only one. You can add your own, though. If it's in your project's classpath, you can use a namespace name (symbol) to identify it. You can also use a string to refer to a Clojure file that will be loaded with load-file. Such pathnames can be absolute or relative to the project root.

  • :fact-filter <a function or keyword>

    The fact filter is the function that the repl tool and lein-midje :filter options override. The filter is given fact metadata; only facts that produce truthy values are loaded or checked. The default fact filter returns true for all facts.

  • :check-after-creation <true or false>

    By default, Midje facts are checked immediately as they're loaded. When set to false, you need to use a repl tool like check-facts to check them. Note that autotest obeys this option.

  • :pretty-print <true or false>

    As of 1.9.0-alpha11, Midje pretty prints datastructures and exceptions. This option allows you to turn it off if you prefer non-structured and non-colorized output for datastructures and exceptions

  • :visible-deprecation <true, false, or :all>

    By default, Midje warns you (once) when you use a deprecated feature. Set the option to false to see no warnings. To see repeated warnings (so you know all the namespaces that need to be fixed), set the option to :all.

  • :visible-future <true or false>

    By default, Midje produces output for future facts (todos). This option can turn off that output.

  • :visible-failure-namespace <true or false>

    By default, Midje prints a filename and line number when a checkable fails. When this option is true, Midje will also print the namespace of the failure.

  • :partial-prerequisites <true or false>

    This option controls what happens when a prerequisite is called with unexpected arguments. Normally, it produces a failure. When this option is set to true, though, prerequisites become partial, which means that a call with unexpected arguments "falls through" to the true function (if it exists). That's useful for testing recursive functions. Remember that you can scope the behavior of prerequisites with with-augmented-config.

  • :colorize <true or false or :reverse>

    This option controls the text output color. See the Colorizing page for more details

Clone this wiki locally