4

我有下一个代码:

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

index方法中,我foo.scala.html使用Twirl. 我想测试这种行为:

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

但我得到了错误:

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

我定义了隐式方法:

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

但我不知道我应该在正文中写什么。谢谢。

4

0 回答 0