2

I am, again, struggling with spray and cannot set up a test correctly. I looked at the similar question spray-testkit: could not find implicit value for parameter ta: and the official spray template and cannot figure out what I am missing and/or doing wrong.

I have a very simple service:

trait SimpleService extends HttpService{

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

And I have a very simple test:

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

when I try to compile this, I get the following error:

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

Can anyone help me and tell me what I am missing? I do not find anything unusual, and I am close to evaluating Play instead of spray.

Community
  • 1
  • 1
rabejens
  • 7,594
  • 11
  • 56
  • 104

2 Answers2

0

You should mixin ScalatestRouteTest before SimpleService, like so:

class SimpleServiceTest extends ScalatestRouteTest with FlatSpec with Matchers with SimpleService

Another possible solution is to add the following lines to where your test throws the Implicit not found:

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

See which line throws, and provide the implicit for that type.

rahilb
  • 726
  • 3
  • 15
-1

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

this solve this problem for my code

Spray.io: Can't compile test spec

Community
  • 1
  • 1