I'm writing Spock tests for my Grails backend. I'm quite new to testing in Grails, and I'm trying to view the response to my mock request.
When I write println(response) I see this in the standard output: org.grails.plugins.testing.GrailsMockHttpServletResponse@62c0fcae
instead of the actual response. Is there anyway to view the contents of this mock http response instead of what is currently being printed?
Just use Groovy's dump method:
Generates a detailed dump string of an object showing its class, hashCode and fields.
println(response.dump())
My example:
def response = new GrailsMockHttpServletResponse()
println(response.dump())
Output:
<org.grails.plugins.testing.GrailsMockHttpServletResponse@6a79c292 outputStreamAccessAllowed=true writerAccessAllowed=true characterEncoding=ISO-8859-1 charset=false content= outputStream=org.springframework.mock.web.MockHttpServletResponse$ResponseServletOutputStream@21a947fe writer=null contentLength=0 contentType=null bufferSize=4096 committed=false locale=en_US cookies=[] headers=[:] status=200 errorMessage=null forwardedUrl=null includedUrls=[]>