Spray.io:无法编译测试规范 [英] Spray.io: Can't compile test spec
问题描述
我有以下服务:
trait PingService extends MyHttpService {
val pingRoutes =
path("ping") {
get {
complete("message" -> "pong")
}
}
}
MyHttpService
是扩展<$ c $的自定义类c> HttpService ,仅包含实用程序方法。
MyHttpService
is a custom class that extends HttpService
and 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屋!