Grails IntegrationSpec和对Controller的多次调用

chu*_*ubs 5 grails integration-testing spock

我有一个测试,我需要使用Grail的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:
    ...
Run Code Online (Sandbox Code Playgroud)

等等等等.问题是尝试更改第二次调用的请求内容,它将无法正常工作.它似乎只保留对request.content的第一次调用.我知道在以前的版本中GroovyTestCase上有帮助方法,但由于我使用Specs,我没有任何方法可以调用来重置控制器的请求/响应.我试图在每个时间之前重新实例化控制器:使用给定的部分:但测试刚刚崩溃.

我必须按此顺序进行这些调用,并测试每次调用之间的状态变化.我无法通过几个方法调用来解决这些问题.在这种情况下,我不确定这是否重要,但我使用的是MongoDB.

在使用Spock IntegrationSpec时,如何多次调用控制器并在每次调用之间重置请求/响应?