Spray.io: Can't compile test spec

巧了我就是萌 提交于 2019-11-29 12:49:00

问题


I have the following service:

trait PingService extends MyHttpService {

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

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

This is the test spec:

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.


回答1:


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



来源:https://stackoverflow.com/questions/27941358/spray-io-cant-compile-test-spec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!