I’m trying to mock the action overview of a Controller, but it isn’t working.
I tried this ways:
MyController.metaClass.overview = { ->
println "MOCKED OVERVIEW"
render(view:"overview", model)
}
MyController.metaClass.demand.overview = { ->
println "MOCKED OVERVIEW"
render(view:"overview", model)
}
MyController.metaClass.static.overview = { ->
println "MOCKED OVERVIEW"
render(view:"overview", model)
}
All this didn’t work.
But i used .metaClass to mock some services, and it worked.
Why with this action isn’t working ?
The println statment is never showed.
Action needs to be there during Grails’ bootstrap – in order to generate URLs and all the Spring beans. You can’t override it (that easy) after application is initialized.
Anyway, you souldn’t need to – actions should be simple. Any testable logic should be testable on its own.