测试spray.io响应

时间:2014-01-04 13:57:36

标签: spray spray-json

我有下一个代码:

//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]] = {
   ???
  }
}

但我不知道我应该写入什么身体。 感谢。

0 个答案:

没有答案
相关问题