Spocktador
Spocktador

Reputation: 17

Expected and Actual not displayed in the console log - Groovy Spock

When I use testResponse.code == 401 I can see the "Expected" and "Actual" from the console log. But when I use checkResponseCode(testResponse, 401) I get the following:

 Condition not satisfied:

checkResponseCode(testResponse, 401)
|         |
false     testpackage.project1.hs.unittestspack.utils.TestClass@17d88132

How do I fix checkResponseCode() method so that it produces expected and actual? Here's the implementation for checkResponseCode():

 static def checkResponseCode(resp, code) {
     resp.code == code
}

Here's the log I want to achieve:

Condition not satisfied:

testResponse.code == 401
|                |    |
|                500  false
testpackage.project1.hs.unittestspack.utils.TestClass@5b367418

Expected :401

Actual   :500

 <Click to see difference>

Upvotes: 0

Views: 433

Answers (1)

Mike W
Mike W

Reputation: 3932

You could assert the condition in your helper method:

static void checkResponseCode( resp, code ) {
    assert resp.code == code
}

Upvotes: 5

Related Questions