There are two specs here. First is not passing because eventually
in check
will not cause whole route rerun but this is the way I would prefer to follow. The second spec is the best solution I found (and prove that it is doable ;) ) but it contains some boilerplate like additional function which in real life will have to return rather tuple than single thing and it is inconsistent with spray-tests syntax design to test routs.
So question is:
How to use eventually
with spray-tests to be as close as possible to syntax from first spec.
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")))
}
}
}
eventually
is used to evaluate repeatedly a value that is changing. So it either has to be avar
, adef
or a byname parameter.The best way around that is probably for you to implement a
checkEventually(times, delay)
method that will incorporate theeventually
call. Something like that: