Spray.io: 无法编译测试规范

Spray.io: Can't compile test spec

我有以下服务:

trait PingService extends MyHttpService {

val pingRoutes =
    path("ping") {
      get {
        complete("message" -> "pong")
      }
    }
}

MyHttpService是自定义 class 扩展 HttpService 并且只包含实用方法。

这是测试规范:

import akka.actor.ActorRefFactory
import org.json4s.{DefaultFormats, Formats}
import org.scalatest.{FreeSpec, Matchers}
import spray.testkit.ScalatestRouteTest

class PingServiceSpec extends FreeSpec with PingService with ScalatestRouteTest with Matchers {

override implicit def actorRefFactory: ActorRefFactory = system

override implicit def json4sFormats: Formats = DefaultFormats

  "Ping service" - {
    "when calling GET /ping" - {
      "should return 'pong'" in {
        Get("/ping") ~> pingRoutes ~> check {
          status should equal(200)
          entity.asString should contain("pong")
        }
      }
    }
  }
}

每当我尝试 运行 测试时,我都会收到以下错误:

could not find implicit value for parameter ta: PingServiceSpec.this.TildeArrow[spray.routing.RequestContext,Unit]

 Get("/ping") ~> userRoutes ~> check {
              ^

我是不是在做傻事?任何形式的帮助将不胜感激!

编辑:虽然这看起来像是 this question 的骗局,但事实并非如此。

其中提供的解决方案post不起作用。

ScalatestRouteTest 已经提供了隐含的 ActorSystem。从您的 actorRefFactory 方法中删除 implicit 修饰符,然后应该执行测试。