我想在每个规范之前开始一项服务,并在每个规范之后关闭它。同时,我希望每个规范都能够使用规范中的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)))我该怎么做?
发布于 2016-03-06 15:16:21
我在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*变量将绑定到(start!)在binding作用域中的结果。
https://stackoverflow.com/questions/35828090
复制相似问题