Grails 2.0 - redirectArgs and forwardArgs

263 views
Skip to first unread message

Dean Del Ponte

unread,
Dec 21, 2011, 9:58:07 AM12/21/11
to Spock Framework - User
redirectArgs and forwardArgs appear to be unavailable when writing
Spock tests for Grails-2.0.0.

What is the recommended way to get these working again?

I see the response.redirectedUrl may be a viable replacement for
redirectArgs. Is this true?

Any equivalent for forwardArgs?

Thanks,

Dean Del Ponte

Luke Daley

unread,
Dec 21, 2011, 9:58:56 AM12/21/11
to spockfr...@googlegroups.com

Using the new test mixins?

Dean Del Ponte

unread,
Dec 21, 2011, 10:09:24 AM12/21/11
to Spock Framework - User
Thanks Luke. Do you happen to have a link to some documentation or an
example?

I found this http://grails.org/doc/latest/guide/testing.html
but I'm not sure what mixin will provide the desired functionality.

- Dean

Luke Daley

unread,
Dec 21, 2011, 10:11:22 AM12/21/11
to spockfr...@googlegroups.com
So you aren't using the new mixins in this test?

> --
> You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
> To post to this group, send email to spockfr...@googlegroups.com.
> To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.
>

Dean Del Ponte

unread,
Dec 21, 2011, 10:16:27 AM12/21/11
to Spock Framework - User
This is a unit test for a controller and I am using
@TestFor(AwesomeController)
@Mock(DomainClassFoo)

forwardArgs and redirectArgs still appear to be unavailable.

I know I'm likely missing (i.e. misunderstanding) something... just
not sure what.

On Dec 21, 9:11 am, Luke Daley <lda...@gmail.com> wrote:
> So you aren't using the new mixins in this test?
>
> On 21/12/2011, at 3:09 PM, Dean Del Ponte wrote:
>
>
>
>
>
>
>
> > Thanks Luke.  Do you happen to have a link to some documentation or an
> > example?
>
> > I found thishttp://grails.org/doc/latest/guide/testing.html

Luke Daley

unread,
Dec 21, 2011, 10:19:06 AM12/21/11
to spockfr...@googlegroups.com

On 21/12/2011, at 3:16 PM, Dean Del Ponte wrote:

> This is a unit test for a controller and I am using
> @TestFor(AwesomeController)
> @Mock(DomainClassFoo)
>
> forwardArgs and redirectArgs still appear to be unavailable.
>
> I know I'm likely missing (i.e. misunderstanding) something... just
> not sure what.

The beauty of these mixins is that they are not Spock specific. You'll have more chance of getting an answer on the Grails list.

Dean Del Ponte

unread,
Dec 21, 2011, 10:20:33 AM12/21/11
to Spock Framework - User
I think I may have figured it out.

I'm awaiting test results, but it looks like references to
redirectArgs now need to be "controller.redirectArgs".


On Dec 21, 9:11 am, Luke Daley <lda...@gmail.com> wrote:
> So you aren't using the new mixins in this test?
>
> On 21/12/2011, at 3:09 PM, Dean Del Ponte wrote:
>
>
>
>
>
>
>
> > Thanks Luke.  Do you happen to have a link to some documentation or an
> > example?
>
> > I found thishttp://grails.org/doc/latest/guide/testing.html

Dean Del Ponte

unread,
Dec 21, 2011, 10:24:17 AM12/21/11
to Spock Framework - User
Spoke too soon. That didn't work.

Thanks for your help. I'll check on the grails mailing list.

- Dean

Jacqui Snook

unread,
Dec 21, 2011, 11:30:04 AM12/21/11
to Spock Framework - User
I had this problem yesterday. I found out that redirectArgs has been
removed. Instead, redirectedUrl on the response object should be used
instead. i.e., for the following,

redirect(controller: 'user', action: 'list')

the test should use

assert response.redirectedUrl == 'user/list'

Sam Carr

unread,
Dec 21, 2011, 5:57:53 PM12/21/11
to spockfr...@googlegroups.com
On 21 December 2011 16:30, Jacqui Snook <jac...@rhindon.com> wrote:
> I had this problem yesterday. I found out that redirectArgs has been
> removed.  Instead, redirectedUrl on the response object should be used
> instead.  i.e., for the following,
>
> redirect(controller: 'user', action: 'list')
>
> the test should use
>
> assert response.redirectedUrl == 'user/list'

I too ran into this when using Grails 2.0 for the first time and
you're right that this is the only way to test it - with
redirectedUrl. I actually raised a JIRA
(http://jira.grails.org/browse/GRAILS-7969) on this issue asking for
the original approach to be made available again as I take issue with
using redirectedUrl. That's testing the UrlMapping as well as the
controller, and I'd like to be able to change my URL mappings without
breaking all my controller unit tests. That's in some senses the whole
point of that particular abstraction after all, if you ask me.

Please vote for the JIRA issue if you agree.

Sam

Howard Lewis Ship

unread,
Dec 22, 2011, 7:56:06 PM12/22/11
to spockfr...@googlegroups.com
Just sent the pull request. Although I set the dependency to 5.3.1 it
should work with 5.2 or better.

> --
> You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
> To post to this group, send email to spockfr...@googlegroups.com.
> To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.
>

--
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

Reply all
Reply to author
Forward
0 new messages