【发布时间】:2015-03-18 00:48:34
【问题描述】:
在我的 Spray 路线中,我委托一个 actor 来处理请求。 RequestContext 在消息中发送给那个演员。
path("mypath") {
parameters("thing".as[String]) { thing => ctx =>
myActor ! ProcessThingAndResondToContext(thing, ctx)
}
}
在我的测试中,我用TestProbe 代替了actor,因为actor 的处理成本很高。
class MySpec extends Specification with Specs2RouteTest with ScalaCheck with MyService {
val testProbe = TestProbe()
override val myActor = testProbe.ref
def is = s2"""
it should $doTheRightThing
"""
def doTheRightThing = {
Get(s"/mypath?thing=fruit") ~> route ~> check {
testProbe.expectMsgClass(classOf[ProcessThingAndResondToContext])
status mustEqual StatusCodes.Success
}
}
此规范失败,因为没有 status。 TestProbe 什么都不做,因此 ctx 从未得到响应。
Request was neither completed nor rejected within 1 second
status mustEqual StatusCodes.Success 行对我的测试并不重要,但我无法删除它,因为那时规范无法编译 - 该方法不再作为 MatchResult 进行类型检查。
如何测试委托给actor的路由?
【问题讨论】:
标签: scala spray specs2 spray-test akka-testkit