jtanistra / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Instance fields should be visible to "where blocks" #195

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
One should be able to parameterize with fixture objects. For example:

class SpecAccount extends Specification
{

Account accA = new Account(13);
Account accB = new Account(25);
Account accC = new Account(45);

def "Account should become ready when one enters the correct code"()
    {
        when: 
        account.receivesCode(codeNumber)

        then: 
        account.isReady()

        where:
        account | codeNumber
        accA    | 13
    accB    | 25
    accC    | 45
    }
}

However, this results in the following error:

     "Only @Shared and static fields may be accessed from here".

If the "where block" is being executed BEFORE the setup method, one is not able 
to access regular instance fields, like the "accA" above.

Can't Spock execute the where block AFTER the setup? It really doesn't make 
sense not being able to access instance fields.

Original issue reported on code.google.com by marcglas...@gmail.com on 10 Aug 2011 at 10:22

GoogleCodeExporter commented 8 years ago
Since every *iteration* of a data-driven feature method has its own spec 
instance, I don't see a sensible way to fix this.

Original comment by pnied...@gmail.com on 4 Oct 2012 at 7:02

GoogleCodeExporter commented 8 years ago
I should also note that this works as designed. I do understand that it may 
seem counter-intuitive at first.

Original comment by pnied...@gmail.com on 4 Oct 2012 at 7:04