我有下一个代码:
//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]] = {
???
}
}
但我不知道我应该写入什么身体。 感谢。