1

我们使用 ratpack 框架构建 REST 服务器和 spock 进行测试。

当条件不满足时(例如堆栈跟踪或响应转储),我需要调整 spock 输出

例如,以下测试:

def "Vk: Auth mr. John"() {
    when:
    request.param "vkId", vkId
    request.param "vkToken", vkToken
    request.port 5050 
    def resp = request.post "/auth/vk"

    then:
    resp.statusCode() == 200
    def json = resp.jsonPath()

    with(json) {
        response != null
        response.token != null
        response.userId != null
    }
}

产生以下错误:

Condition not satisfied:

resp.statusCode() == 200
|    |            |
|    500          false
com.jayway.restassured.internal.RestAssuredResponseImpl@10b033e

如何让 spock 提供更多详细信息,例如响应正文?

4

1 回答 1

1

认为您必须执行以下操作:

assert resp.statusCode == 200,
       "resp.statusCode == $resp.statusCode (not 200) $resp.body"
于 2013-11-22T11:39:23.260 回答