【发布时间】:2015-11-11 21:32:19
【问题描述】:
我在 Grails 2.3.6 中有一个 IntegrationSpec 测试,它创建任何控制器的实例,将数据添加到主体(通过 controller.request.JSON),然后验证它是否已正确设置。
问题是当我添加@Stepwise注解时,似乎将request对象锁定在controller对象上。在调试器中,我看到它是同一个对象(基于哈希码),正如您在下面的测试失败中看到的那样,第二次使用 where: 块中的值运行测试时,它失败了,因为第一次where: 块中的值仍然存在。
@Stepwise
class TestSpec extends IntegrationSpec {
@Unroll
void "changing controller request"() {
setup:
SomeController controller = new SomeController()
when:
controller.request.JSON = json
then:
controller.request.JSON == json
where:
json << [
[one: "1"],
[two: "2"]
]
}
}
这是失败的消息。
controller.request.JSON == json
| | | | |
| | | | [two:2]
| | | false
| | [one:1]
| org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpServletRequest@55906c66
com.package.SomeController@7b044602
如果我删除@Stepwise,这不会失败。
有什么方法可以强制重新创建request 对象,或者覆盖之前测试设置的值?
【问题讨论】:
-
相信controlup.response.reset() in cleanup: in the feature方法也能解决这个问题。
标签: grails grails-2.0 spock