I have a test where I need to make several calls back to back to test a controller using Grail's IntegrationSpec.
when: "User starts a flow"
controller.userSessionService.user = user
controller.request.method = "POST"
controller.request.contentType = "text/json"
controller.request.content = ([lId: l.id] as JSON).toString().getBytes()
controller.start()
then:
...
when: "User does next step"
controller.userSEssionService.user = user
controller.request.method = "POST"
controller.request.contentType = "text/json"
controller.request.content = ([data1: data] as JSON).toString().getBytes()
controller.nextStep()
then:
...
So forth and so on. The problem is trying to change the request's content for the 2nd call and it won't work. It seems to keep only the first call to request.content. I know in prior versions there were helper methods on GroovyTestCase, but since I'm using Specs there aren't any methods I can call to reset the request/response for a controller. I've tried to re-instantiate the controller before each when: sections using given:. But the test just crashed.
I have to make these calls in this order and test the state changes between each call. I can't break these up across several method calls. I'm not sure this matters in this case, but I'm using MongoDB.
How do I make multiple calls to the controller and have the request/response reset between each call when using Spock IntegrationSpec?