Search code examples
testinggrailsrendercontrollers

how do I test grail's controller's render method?


How do I test this:

render view: "create", model: [user: user]

I know how to test redirectArgs and stuff, but I can't find an example to test something like this. It seems like articles and stuff go out of their way to not test this....


Solution

  • renderArgs is what you want. (From ControllerUnitTestCase)

    E.g to test that the correct view will be rendered

    assertEquals 'create', renderArgs.view
    

    Check the model

    assertEquals user, renderArgs.model.user
    

    Make sure that your test extends ControllerUnitTestCase

    Etc etc