marick/Midje

Do not test on namespace load

Closed this issue · 1 comments

I have midje.sweet/facts defined on top level. This causes tests to be executed each time namespace is loaded. Is this expected? Why?

What is suggested way to declare my Midje tests so they are only executed when tests are requested (e.g. when I examine them in REPL or launch "lein midje")? I want to avoid side-effects on namespace load since this interferes with code analyzers e.g. Eastwood's Leiningen plugin or namespace loading tools like clojure.tools.namespace.

It is expected. It's that way because I like that test namespaces containing non-test code execute as they read. (That is, a freestanding form before a fact cannot have its effect erased by another form after the fact.) That's a bad idea in theory, but I find it makes for more understandable test namespaces in practice.

To change that, set the configuration option :check-after-creation to false. You can then use check-facts to run the tests.