A Techie Writer's Block

Programming to go!

Testing flash.message in a Grails Webflow

Leave a comment

Say, you write something like this in your webflow:

...
if (some_condition) {
   flash.message = "my error message"
   return error()
}
...

To access this in the GSP page, you use:

<g:if test="${message}">
...
</g:if>

instead of the usual

<g:if test="${flash.message}">
...
</g:if>

due to the issue with accessing flash-scoped objects with webflows. Now, the question is, while writing tests, how do you go about accessing this object?

Instead of using controller.flash.message, do this instead:

void testSomething() {
   assertTrue controller.request.message ==~ /some text/
}

… which does the trick 😉

Author: Lee

Just an ordinary software engineer who happens to have dabbled in a lot of different technologies over the years... :p

Leave a comment