Midje
Midje copied to clipboard
remove-ns before loading
Midje doesn't remove the namespaces it reloads, which causes old symbols to stick around and cause confusion.
Steps to reproduce:
- Create a file
mytest.clj
(ns mytest (:use [midje.sweet]))
(def x 1)
(fact x => 1)
- Run
(autotest)
. It loadsmytest
, checks the fact and succeeds.
Using a new REPL / lein midje
run for the next steps behaves as expected, using the same REPL / lein midje :autotest
run behaves unexpected:
- Remove the
(def x 1)
line. Autotest reloads and succeeds! - Change
(fact x => 2)
, autotest reloads and fails withActual: 1, Expected: 2
. - Run
(remove-ns 'mytest)
. Save the file again. - Now the test fails as expected with a load failure: unable to resolve x. (and then autotest stops without the autotest has been cancelled message it seems)
Prior to loading the changed namespaces there should be a step where midje runs remove-ns
for all of them. The documentation says "use with caution" though, so maybe it breaks things(?), in that case an option like (autotest :remove-ns)
would be nice.
I will experiment with remove-ns
in upcoming alphas.