我尝试为喷雾编写测试
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(unknown token Near: ,Some(org.json4s.ParserUtil$ParseException: unknown token Near: ))
如何将自动解码 GZIP HttpResponse 设置为字符串?