Using interaction parameters in custom return value

20 views
Skip to first unread message

Steve Appling

unread,
Dec 20, 2010, 4:03:43 PM12/20/10
to Spock Framework - User
When writing a custom return value for an interaction, is there any
way to access the actual parameter that was used?

Something like:

test.getValue(int key) >> { return func(key) }

Peter Niederwieser

unread,
Dec 20, 2010, 5:00:23 PM12/20/10
to spockfr...@googlegroups.com
On 20.12.2010, at 21:03, Steve Appling wrote:

> When writing a custom return value for an interaction, is there any
> way to access the actual parameter that was used?

The method arguments are passed to the closure. Therefore, Groovy allows you to do things like:

foo.bar(_, _) >> { args -> args[0] }

foo.bar(_, _) >> { one, two -> one }

Cheers,
Peter

Steve Appling

unread,
Dec 21, 2010, 8:15:08 AM12/21/10
to Spock Framework - User
Great! That would be useful to mention on the interactions wiki page.
Reply all
Reply to author
Forward
0 new messages