【问题标题】:Spray, ScalaTest and HTTP services: could not find implicit value for parameter ta:Spray、ScalaTest 和 HTTP 服务:找不到参数 ta 的隐含值:
【发布时间】:2015-12-04 22:42:51
【问题描述】:

我再次遇到喷雾问题,无法正确设置测试。我查看了spray-testkit: could not find implicit value for parameter ta:official spray template 的类似问题,无法弄清楚我错过了什么和/或做错了什么。

我有一个非常简单的服务:

trait SimpleService extends HttpService{

  val fooRoute = path("foo") {
    get {
      complete("bar")
    }
  }
}

我有一个非常简单的测试:

class SimpleServiceTest extends FlatSpec with Matchers with SimpleService with ScalatestRouteTest {

  override implicit def actorRefFactory: ActorRefFactory = system

  "The service" should "return OK status when getting /foo" in {
    Get("/foo") ~> fooRoute ~> check {
      status should be(OK)
    }
  }
}

当我尝试编译它时,我收到以下错误:

Error:(17, 17) could not find implicit value for parameter ta: SimpleServiceTest.this.TildeArrow[spray.routing.RequestContext,Unit]
Get("/foo") ~> fooRoute ~> check {
            ^

谁能帮助我并告诉我我缺少什么?我没有发现任何异常情况,而且我即将评估 Play 而不是 Spray。

【问题讨论】:

    标签: scala spray scalatest


    【解决方案1】:

    你应该在SimpleService之前混入ScalatestRouteTest,像这样:

    class SimpleServiceTest extends ScalatestRouteTest with FlatSpec with Matchers with SimpleService
    

    另一种可能的解决方案是将以下行添加到您的测试引发未找到隐式的位置:

    implicitly[spray.testkit.RouteTestTimeout] 
    implicitly[spray.routing.RoutingSettings] 
    implicitly[spray.util.LoggingContext] 
    

    查看抛出哪一行,并提供该类型的隐式。

    【讨论】:

    • FlatSpec 必须是第一个,因为它不是一个特征,但我就是这样做的,并且遇到了同样的错误。
    • 我终于放弃了,转而使用 Play。
    【解决方案2】:

    ScalatestRouteTest 已经提供了一个隐式的 ActorySystem。从您的 actorRefFactory 方法中删除 "implicit" 修饰符,测试应该会被执行。

    这为我的代码解决了这个问题

    Spray.io: Can't compile test spec

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      • 2018-06-29
      • 1970-01-01
      • 2017-04-26
      相关资源
      最近更新 更多