这里有两个规格。首先是不通过,因为eventually
incheck
不会导致整个路线重新运行,但这是我更愿意遵循的方式。第二个规范是我找到的最好的解决方案(并证明它是可行的;))但它包含一些样板,如附加函数,在现实生活中必须返回元组而不是单一的东西,它与喷雾测试语法设计不一致测试路线。
所以问题是:
如何使用eventually
喷雾测试尽可能接近第一个规范的语法。
import org.specs2.mutable.Specification
import spray.routing.Directives
import spray.http._
import MediaTypes._
import HttpCharsets._
import spray.testkit.Specs2RouteTest
class EventuallyAndRouts extends Specification with Directives with Specs2RouteTest {
var i = 0
def incAndGet = {
i = i + 1
println(s"This is i = $i")
s"$i"
}
"The testing infrastructure should support an eventually matcher" >> {
"but it is not working inside a check as I need :( (and this will fail)" in {
i = 0
Get() ~> complete(incAndGet) ~> check {
body must eventually(7, 20 millis)(be_===(HttpEntity(ContentType(`text/plain`, `UTF-8`), "5")))
}
}
"so I got workaround :/ (and this is passing)" in {
i = 0
def requestResult = Get() ~> complete(incAndGet) ~> check {
body
}
requestResult must eventually(7, 20 millis)(be_===(HttpEntity(ContentType(`text/plain`, `UTF-8`), "5")))
}
}
}