Note that there are some explanatory texts on larger screens.

plurals
  1. POGrails 2.0: Issue testing flash.message
    text
    copied!<p>I have a unit test for my <code>UserController</code> but since upgrading to Grails 2.0, the <code>flash</code> variable always seems to return an emtpy map with no message.</p> <p>Here are some code snippets of the <code>UserControllerTests</code>:</p> <pre><code>@TestFor(UserController) @Mock(User) class UserControllerTests { ... void testSaveSucceeds() { params.userName = 'Joe' ... controller.save() assert null != flash.message assert '/user/list' == response.redirectedUrl } } </code></pre> <p>In <code>UserController</code>:</p> <pre><code>def save = { def userInstance = new User(params) if (userInstance.validate()) { flash.message = message(code: 'default.created.message', args: [userInstance.userName ]) ... } </code></pre> <p>But my test result is as follows:</p> <pre><code>assert null != flash.message | | | | [:] null false </code></pre> <p>I have tried as an integration test as well because otherwise the <code>response</code> was null as weill but it did not fix the flash issue. The same problem also exists with <code>view</code> and <code>model</code>.</p> <p>What am I missing? Any help highly appreciated.</p> <p>Regards</p> <p>Jonas</p> <p><strong>EDIT:</strong></p> <p>Here's a weird scenario:</p> <p>My controller has the following:</p> <pre><code>def test = { flash.message = "Message" } def save = { flash.message = "Message" } </code></pre> <p>My Test looks like that:</p> <pre><code>void testSaveSucceeds() { controller.save() println "&gt;&gt;&gt; ${flash}" controller.test() println "&gt;&gt;&gt; ${flash}" } </code></pre> <p>The output like that:</p> <pre><code>&gt;&gt;&gt; [:] &gt;&gt;&gt; [message:Message] </code></pre> <p>Interesting to mention is also that the debugger in IntelliJ stops at a breakpoint in the test() action but not in save()</p> <p>HOW can that be????</p> <p>Regards</p> <p>Jonas</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload