[英]Unit testing Grails controller chaining
I am unable to figure out how to test for a controller action that does 'chain'. 我无法弄清楚如何测试执行“链式”操作的控制器。 I would like to verify the action. 我想验证操作。
Grails: 2.4.2 谷物:2.4.2
Controller: 控制器:
class MyController {
def index() {
}
def doesChain() {
chain action: 'index', model: [name: "my name"]
}
} }
Test: 测试:
@TestFor(MyController)
class MyControllerSpec extends Specification {
def setup() {
}
def cleanup() {
}
void "Action doing chain"() {
when:
controller.doesChain()
then:
controller.chainModel.name == "my name"
controller.actionName == "someAction" // fails as actionName == null
}
} }
Testing the action name is not passing as the actionName appears to be null. 测试动作名称没有通过,因为actionName似乎为空。
You could do something like this... 你可以做这样的事情...
@TestFor(MyController)
class MyControllerSpec extends Specification {
void "Action doing chain"() {
when: 'an action invokes the chain method'
controller.doesChain()
then: 'the model is as expected'
// either of these should work, you don't need both...
controller.chainModel.name == "my name"
flash.chainModel.name == "my name"
and: 'the redirect url is as expected'
response.redirectUrl == '/my/index'
}
}
I hope that helps. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.