0

I could not find any Midje function that runs after all facts.

Here is the code:

(background
  (before :contents (println "Before All Facts"))
  (after :contents (println "After All Facts"))
  (before :facts (println "Before Each Fact"))
  (after :facts (println "After Each Fact")))

Actual Output is:

Before All Facts
After All Facts
Before Each Fact
After Each Fact

Expected Output is:

Before All Facts
Before Each Fact
After Each Fact
After All Facts
Ertuğrul Çetin
  • 5,131
  • 5
  • 37
  • 76
  • Here is the github issue: https://github.com/marick/Midje/issues/374 – Ertuğrul Çetin Nov 12 '16 at 23:17
  • This doesn't seem to be a question, but a bug -- one which the author feels cannot be fixed apparently, at least according to your github issue. – schaueho Nov 13 '16 at 15:08
  • It's a bug in a deprecated feature, `background`. The feature has been replaced with `with-state-changes` and `namespace-state-changes`, which do support what you want. – Conan Nov 15 '16 at 15:05

1 Answers1

1

You can wrap all your facts in a with-state-changes to achieve this, but beware that Clojure has a limit to the maximum size of a top-level form. To avoid that problem you can use namespace-state-changes to perform setup and teardown at the beginning and end of an entire file.

Conan
  • 2,288
  • 1
  • 28
  • 42
  • I need AfterClass not After :) I guess Midje does not support this. – Ertuğrul Çetin Nov 15 '16 at 15:47
  • You can run code after all your facts this way, producing the output in your question. It won't be possible to interrupt execution after the actual namespace has been executed. Why do you need to do that? – Conan Nov 15 '16 at 15:51
  • Those links have good examples, I'm not sure I could add much I'm afraid. You could also investigate moving away from midje and using fixtures from clojure.test with the `:once` flag – Conan Nov 15 '16 at 17:18
  • Essentially you just need to replace `background` with `with-state-changes` and put all the before/after forms in a vector – Conan Nov 15 '16 at 17:21