1

We use ratpack framework for building REST server and spock for testing.

I need to tune spock output when condition unsatisfied (eg. stacktrace or response dump)

For example, following test:

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
    }
}

Produces following error:

Condition not satisfied:

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

How can I make spock to provide more details such as response body?

ruX
  • 7,224
  • 3
  • 39
  • 33

1 Answers1

1

I think you have to do something like:

assert resp.statusCode == 200,
       "resp.statusCode == $resp.statusCode (not 200) $resp.body"
tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • Another option is to include `resp.body` in the assertion. – Peter Niederwieser Nov 22 '13 at 12:15
  • Thank you, great hint. But once I get result ```assert resp.statusCode() == 200, "not 200 ${resp.body().print()}"``` I get ```IOException: Attempted read on closed stream``` coz already read data in substituted string – ruX Nov 23 '13 at 10:22