10

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.

Community
  • 1
  • 1
Matteo Pacini
  • 21,796
  • 7
  • 67
  • 74

1 Answers1

20

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

akauppi
  • 17,018
  • 15
  • 95
  • 120
edi
  • 3,112
  • 21
  • 16
  • 1
    The above error arises as a consequence from an implicit ambiguity, because you have two implicit `ActorRefFactory` in scope. The one from the [`ScalatestRouteTest`](http://spray.io/documentation/1.1-SNAPSHOT/api/index.html#spray.testkit.RouteTest) the `PingServiceSpec` is based on and the one declared explicitly as `actorRefFactory`. – edi Nov 21 '15 at 16:53
  • 1
    Thank you! But why exception mentions `could not find implicit value for parameter ta` (which is `implicit ta: TildeArrow[A, B]`) instead of actorRefFactory? – Observer Nov 22 '15 at 01:32
  • 1
    I think because the compiler currently doesn't tell us, see [SI-6127](https://issues.scala-lang.org/browse/SI-6127) for more info. – edi Nov 22 '15 at 20:16