Spray说任何正常的数据类型,包括Seq
,都会自动地(未)与JSON进行混合。出于某种原因,我没有遇到过这种情况。
import spray.json._
import DefaultJsonProtocol._
...
class RestAPITest
extends FlatSpec
with Matchers
with ScalatestRouteTest
with MyRoute
{
...
behavior of "MyRoute"
it should "return a list as JSON" in {
Get("/computers") ~> myRoute ~> check {
status should equal(OK)
// 'sbt test' gives:
// "could not find implicit value for evidence parameter of type spray.httpx.unmarshalling.FromResponseUnmarshaller[Seq[String]]"
//
responseAs[Seq[String]] should contain theSameElementsAs( List( "A01", "A02", "A03", "E01", "G04" ) )
}
}
我做错了什么?
答案 0 :(得分:0)
将spray.httpx.SprayJsonSupport
特征中的混合添加到我的测试类中,以明确发生了什么。这件作品只是一颗宝石 - 让JSON REST API测试基本上是单行!高兴。
http://spray.io/documentation/1.1-SNAPSHOT/spray-httpx/spray-json-support/
谢谢@jrudolph:)