我希望在每个规范之前启动服务,并在每个规范之后将其关闭。同时我希望每个规范都能够使用规范中的service
。例如(它不起作用):
(describe
"Something"
(around [it]
(let [service (start!)]
(try
(it)
(finally
(shutdown! service)))))
(it "is true"
; Here I'd like to use the "service" that was started in the around tag
(println service)
(should true))
(it "is not false"
(should-not false)))
我该怎么做?
答案 0 :(得分:1)
我无法在speclj中看到它的直接支持,并且其内部设计不允许使用此类功能扩展它。但是,您可以使用动态范围来实现它:
(declare ^:dynamic *service*)
(describe
"Something"
(around [it]
(binding [*service* (start!)]
(try
(it)
(finally
(shutdown! *service*)))))
(it "is true"
(println *service*)
(should true))
(it "is not false"
(should-not false)))
*service*
var将绑定到(start!)
范围内binding
的结果。