1

First time spray user close to ripping hair out.

trait SampleService extends SimpleRoutingApp with JsonProtocol with SprayJsonSupport {

  implicit val system: ActorSystem = ActorSystem("test")

  implicit def context: ExecutionContext = system.dispatcher

  startServer(interface = "localhost", port = 8888) {
    path("test") { _ =>
      get {
        complete {
          "test"
        }
      }
    }
  }
}

import org.scalatest.FlatSpec import spray.testkit.ScalatestRouteTest

class ApiSpec extends FlatSpec with ScalatestRouteTest with SampleService {

  "The api service" should "return test" in {
    Get("/test/") ~> check {
      responseAs[String] === "test"
    }
  }
}

And the wonderful compilation error message:

 could not find implicit value for parameter ta: ApiSpec.this.TildeArrow[ApiSpec.this.RouteResult,Boolean]
[error]     Get("/test/") ~> check {}

Could anyone please point me in the right direction? Copy pasting from spray-testkit examples seems to fail.

flavian
  • 28,161
  • 11
  • 65
  • 105
  • 3
    The basic syntax using testkit is `request ~> route ~> check {}`. You are missing the `route` part. You need to put the route (starting with `path("test")`) into a `def` where you can access it from the documentation. The official spray-template project shows a common basic architecture of how to build easily testable apps. https://github.com/spray/spray-template/blob/on_spray-can_1.3_scala-2.11/src/main/scala/com/example/MyService.scala – jrudolph Feb 24 '15 at 08:54
  • You might be also missing the `spray.json._` import – Niko Jul 05 '21 at 12:49

0 Answers0