我正在尝试使用喷涂路线并想使用 Spray-TestKit 对其进行测试。我正在使用: - Scala 2.10.3 - Akka 2.3.3 - Spray 1.3.1
我创建了一个扩展 HttpService 的特征,我在其中定义了一个路由:
trait MyService extends HttpService with CoreAccess {
import greentee.am.endpoint.tsmsp.tsmSPJsonSupport._
val myRoute = {
path("resources"/"ping") {
get {
complete(OK, "pong")
}
}
}
}
我删除了部分不相关的路线。CoreAccess 是一个扩展 Actor 的 trait,因为我在该 trait 中有访问 ActorSystem 的方法。(我不知道谁在不扩展演员的情况下从特征中检索 ActorSelection )
然后我创建一个测试规范
import MyService
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
import spray.http.StatusCodes._
class RegistrationRouteSpecification extends Specification with Specs2RouteTest with MyService {
def actorRefFactory = system
"The EndPoint " should {
"return Pong to a Get request to the ping" in {
Get("/resources/ping") ~> myRoute ~> check {
status === OK
responseAs[String] === "pong"
}
}
}
}
当我尝试执行测试时,出现以下编译错误:
[info] Compiling 1 Scala source to /Users/IdeaProjects/endpoint/target/scala-2.10/test-classes...
[error] /Users/IdeaProjects/endpoint/src/test/scala/RegistrationRouteSpecification.scala:19: could not find implicit value for parameter ta: RegistrationRouteSpecification.this.TildeArrow[spray.routing.RequestContext,Unit]
[error] Get("/resources/ping") ~> myRoute ~> check {
[error] ^
[error] one error found