Spray.io:无法编译测试规范 [英] Spray.io: Can't compile test spec

查看:79
本文介绍了Spray.io:无法编译测试规范的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下服务:

trait PingService extends MyHttpService {

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

MyHttpService 是扩展<$ c $的自定义类c> HttpService ,仅包含实用程序方法。

MyHttpServiceis a custom class that extends HttpServiceand only contains utility methods.

这是测试规范:

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")
        }
      }
    }
  }
}

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

Whenever I try to run the tests, I get the following error:

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

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

我在做愚蠢的事情吗?

Am I doing something stupid? Any kind of help will be appreciated!

编辑:尽管这看起来像是对这个问题,不是。

EDIT: Although this might look like a dupe of this question, it's not.

该帖子中提供的解决方案无效。

The solution provided in that post it's not working.

推荐答案

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

The ScalatestRouteTest already provides an implicit ActorSystem. Remove the implicit modifier from your actorRefFactory method and the test should get executed.

这篇关于Spray.io:无法编译测试规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆