【发布时间】:2015-03-03 21:05:15
【问题描述】:
我尝试编写喷雾测试
class FullTestKitExampleSpec extends Specification with Specs2RouteTest with UserController with HttpService {
def actorRefFactory = system
"The service" should {
"return a greeting for GET requests to the root path" in {
Get("/user") ~> `Accept-Encoding`(gzip) ~> userRoute ~> check {
val responsex = response
responseAs[String] must contain("Test1")
}
}
}
}
我有关注路由器
trait UserController extends HttpService with Json4sSupport with CORSSupport{
override implicit def json4sFormats: Formats = DefaultFormats
val userRoute = {
cors {
compressResponse(Gzip) {
path("user") {
get {
complete {
"Test1"
}
} ~
post {
entity(as[UserRegister]) { person =>
complete {
println(person.name)
person.name
}
}
}
}
}
}
}
}
我使用 GZIP 压缩来响应,但是
无法解组对
responseAs断言的类型“java.lang.String”的响应:MalformedContent(未知令牌 Near: ,Some(org.json4s.ParserUtil$ParseException: 未知令牌 附近:))
如何将 GZIP HttpResponse 自动解码为字符串?
【问题讨论】:
标签: scala spray spray-json spray-client spray-test