以下代码有效(显然):
(use [midje.sweet])
(with-state-changes [(before :contents (println "setup") :after (println "teardown"))]
(fact "one"
(println "doing 1")
1 => 1)
(fact "two"
(println "doing 2")
(+ 1 1) => 2))
输出是预期的:
setup
doing 1
doing 2
teardown
但我想将我的事实分组在一个单独的函数中,如下所示:
(defn my-facts []
(fact "one" ...)
(fact "two" ...)
#_( ... ))
(with-state-changes [(before :contents (println "setup") :after (println "teardown"))]
(my-facts))
这次 midje 无法执行代码,我收到以下错误:
Midje could not understand something you wrote:
Background prerequisites created by the wrapping version of
`against-background` only affect nested facts. This one
wraps no facts.
Note: if you want to supply a background to all checks in a fact,
use the non-wrapping form. That is, instead of this:
(fact
(against-background [(f 1) => 1]
(g 3 2 1) => 8
(h 1 2) => 7))
... use this:
(fact
(g 3 2 1) => 8
(h 1 2) => 7
(against-background (f 1) => 1))
有什么方法可以实现我的目标吗?我想使用 midje 的设置和拆卸工具,但仍然能够将我的事实包含在单独的fn
.