我不知道如何测试一个控制器动作,做‘链’。我想核实一下这一行动。
Grails: 2.4.2
主计长:
class MyController {
def index() {
}
def doesChain() {
chain action: 'index', model: [name: "my name"]
}}
测试:
@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
}}
测试操作名没有传递,因为actionName似乎是空的。
发布于 2014-07-23 13:49:55
你可以这样做..。
@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'
}
}我希望这能帮上忙。
https://stackoverflow.com/questions/24909675
复制相似问题