下面的代码可以工作(很明显):
(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中。
发布于 2015-07-06 21:33:09
我花了一些时间查看了Midje的源代码,我认为这是不可能的。在宏扩展期间,Midje严重依赖于解析和重写代码,当它获得您的单独函数调用的结果时,Midje宏(事实等)已经被扩展和评估。如果你真的下定决心,你可能会做到这一点,但它将不得不使用宏的单独事实,而不是一个函数,以便让Midje访问您的原始事实表单。Midje在很大程度上都是宏,所以很难使用其他任何东西来与之交互。
https://stackoverflow.com/questions/31243695
复制相似问题