I just struggled with this problem. To figure it out, I waded through the Akka HTTP codebase, which is a jungle of implicit
s.
My problem seemed to be that without the right secondary implicit
in place, the correct TildeArrow
instance wasn't being found. If you look at the code, the TildeArrow
instance, which is required in the error message, is defined as an implicit def injectIntoRoute
in the companion object and it requires a whole host of other implicit
s.
I suggest writing out your code without any of the implicit sugar. This should better help the compiler give you a proper error message:
"MyProxy" should {
"return a json for GET requests to the /api/getclass/classCode path for a regular request" in {
val request = Get("/api/getclass/123/")
val requestWithRoutes = request.~>(myRoutes)(TildeArrow.injectIntoRoute)
requestWithRoutes.~>(check {
responseAs[String] must contain("classCode")
contentType === ContentTypes.`application/json`
})
}
}
I think the reason is that since there's no concrete instance of the implicit
available, the compiler is trying to satisfy the implicit resolution with the abstract class TildeArrow
, and the completely unspecified abstract type
, ta.Out
, doesn't have a ~>
defined.
In my specific case, I was missing an implicit ExecutionContextExecutor
, whatever that means.
UPDATE
Actually, I looked into it further and the problem was that I had an implicit def ec: ExecutionContextExecutor
declared in my route trait, but trait RouteTest
defines its name as executor
, and so when I defined my own to fulfill the missing implicit, I ended up with two of the same implicit.
It's a cute API, but the implicit magic is way out of control, IMO, especially given how cryptic the error messages tend to be.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…