Re: Is it possible to parameterize a Spec name with a value from a data table?

107 views
Skip to first unread message

Peter Niederwieser

unread,
Oct 15, 2012, 11:30:13 PM10/15/12
to spockfr...@googlegroups.com
Yes there is. You just have to annotate the method or class with @spock.lang.Unroll. Then use `#role`, `#landingPage`, etc. in the method name.

Cheers,
Peter

On Oct 16, 2012, at 1:06 AM, olivier nguyen <olivi...@gmail.com> wrote:

Hello everyone,

I am wondering if it is possible to parameterize the name of a spec with a value from a data table to know which scenario failed.

For example, I have:


def "checks access to dashboard as a(n) #role"(){

setup:

to LoginPage

login(role)


when:

at HomePage

searchModule.submitSearch testAccount.email


then:

at landingPage


cleanup:

topMenu.logout()


where:

role         | landingPage

"ADMIN" | DashboardPage

"OPERATOR" | DashboardPage

"FINANCE" | DashboardPage

"VOUCHER" | SearchIndexPage

}


So depending on a role, I am supposed to land on a different page.

I wish there is a way to say: "checks access to dashboard as a(n) ADMIN" failed.

 

Thanks!

 


--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To view this discussion on the web visit https://groups.google.com/d/msg/spockframework/-/lIROyjZieS8J.
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.

olivier nguyen

unread,
Oct 16, 2012, 4:27:22 PM10/16/12
to spockfr...@googlegroups.com
Thank you Peter.

I saw the @Unroll annotation before in some docs but it wasn't intuitive at a glance what it was used for.

Anyways, thank you! 

David De Groot

unread,
Feb 24, 2016, 8:01:54 PM2/24/16
to Spock Framework - User, olivi...@gmail.com
Hello,

If you add @Unroll at the spec / class level, how do you annotate the list of values that you'd like to loop through? I tried adding a "where:" after the last feature method in my Spec, but spock is complaining.

Could someone give an example of how to loop through a list of values or a Map such as this when @Unroll is specified at the spec level:

where:

role          | landingPage

"ADMIN" | DashboardPage

"OPERATOR" | DashboardPage

"FINANCE" | DashboardPage

"VOUCHER" | SearchIndexPage


Thanks!

David 

Kostis Kapelonis

unread,
Mar 8, 2016, 5:05:07 PM3/8/16
to spockfr...@googlegroups.com
The documentation of @Unroll is pretty clear

"The Unroll annotation can also be put on a spec class. This has the
same effect as putting it on every data-driven feature method that is
not already annotated with Unroll"

Unroll affects the name of the feature (i.e. the unit test method).
Putting it on the Spec level does not mean that it affects the Spec
name in any way. It is just a shortcut that saves you time for placing
it over all features (Imagine that you have a class with 20 methods).

Also, all Spock blocks exist inside methods only. Putting a where:
block outside of a feature is not supposed to work. The hierarchy is
Spec -> feature -> block. A Specification (class), contains features
(methods), that themselves contain blocks (labels).

Kostis
> To unsubscribe from this group and stop receiving emails from it, send an
> email to spockframewor...@googlegroups.com.
> To post to this group, send email to spockfr...@googlegroups.com.
> Visit this group at https://groups.google.com/group/spockframework.
> For more options, visit https://groups.google.com/d/optout.

David De Groot

unread,
Mar 9, 2016, 1:12:22 AM3/9/16
to spockfr...@googlegroups.com

Ah. Gotcha. Thanks.

You received this message because you are subscribed to a topic in the Google Groups "Spock Framework - User" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spockframework/oqx8FpgSlkQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to spockframewor...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages