The answer to the spray test.

I have the following code:

//models
case class Foo(name: String, age: Option[Int] = None)

//routing
trait FooRouting extends HttpService {
   def index(foos: List[Foo]): twirl.api.Html = html.foo.render(foos) 

   val route = 
     path("") {
       get { complete( index(Foo.all) } } 
     }
}

In the method index, I draw a template foo.scala.htmlwith Twirl. I want to check this behavior:

 //tests
 class FooTests extends FunSpec with Matchers
  with ScalatestRouteTest { 
    def actorRefFactory = system

    val t0 = Foo("test0")
    val t1 = Foo("test1") 

    it("test foo") {
      Get() ~> r ~> check {
        responseAs[List[Foo]] should be(List(t0, t1))
      }
     }
 }

But I got the error:

Tests.scala:49: could not find implicit value for evidence parameter of type spray.httpx.unmarshalling.FromResponseUnmarshaller[List[pack.Foo]] [error] responseAs[List[Foo]] should be(List(t0, t1))

I define an implicit method:

implicit val foo2response = new FromResponseUnmarshaller[List[Foo]] {
  def apply(r: HttpResponse): Deserialized[List[Foo]] = {
   ???
  }
}

But I do not know what I should write to the body. Thanks.

+4
source share

All Articles