Class-level where clause

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Class-level where clause

Tobia Conforto
Hello

I have a spec for a number of simple properties of the same class. Right now my code looks like this:

    static final PARAMS = [...]

    def "propertyA"() {
        def object = (create object according to params)

        expect:
        object.propertyA == (some expression based on params)

        where:
        params << PARAMS
    }

    def "propertyB"() {
        def object = (create object according to params)

        expect:
        object.propertyB == (some other expression based on params)

        where:
        params << PARAMS
    }

    ...

Is there a way to declare all my feature methods as data-driven out of the same table, in this case PARAMS, so that I can omit the where: block from every feature method and move the object initialization in a setup()?

I tried putting the where: block in a setup() but it's not recognized.

Tobia

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Class-level where clause

Peter Niederwieser
Administrator
This is a common (and sensible) feature request, but it isn’t currently supported.

On 04 Apr 2015, at 21:46, Tobia Conforto <[hidden email]> wrote:

Hello

I have a spec for a number of simple properties of the same class. Right now my code looks like this:

    static final PARAMS = [...]

    def "propertyA"() {
        def object = (create object according to params)

        expect:
        object.propertyA == (some expression based on params)

        where:
        params << PARAMS
    }

    def "propertyB"() {
        def object = (create object according to params)

        expect:
        object.propertyB == (some other expression based on params)

        where:
        params << PARAMS
    }

    ...

Is there a way to declare all my feature methods as data-driven out of the same table, in this case PARAMS, so that I can omit the where: block from every feature method and move the object initialization in a setup()?

I tried putting the where: block in a setup() but it's not recognized.

Tobia

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.