我有许多midje事实,它们的设置/拆卸几乎是相同的,但并不完全相同。
(against-background [(before :contents (setup!)) (before :contents (data)) (before :facts (set-access)) (after :contents (teardown!)]
(facts "about this thing i am testing "
; ...
))
(against-background [(before :contents (setup!)) (before :contents (data)) (before :facts (set-other-access)) (after :contents (teardown!)]
(facts "about this other thing i am testing "
; ...
))我想把背景包装成一些可重用的东西,最好是可参数化的,这样我就可以重用它们,但这样做有困难。Midje告诉我,除了上述之外,任何其他内容都不是预期的背景形式。
发布于 2012-02-12 02:49:16
Midje没有能力做你所要求的事情。如果您希望这样做,请考虑将其作为问题添加到此处:https://github.com/marick/Midje/issues?sort=updated&direction=desc&state=open&page=1
一种解决方案是创建您自己的宏来执行此操作。(未测试)
(defmacro against-my-background [docstring & body]
`(against-background [(before :contents (setup!))
(before :contents (data))
(before :facts (set-access))
(after :contents (teardown!)]
(facts ~docstring
~@body )))
;; usage
(against-my-background "about this thing i am testing"
(fact (foo) => :bar)
(fact (foo) =not=> :baz))https://stackoverflow.com/questions/9239728
复制相似问题