djcrankypants / spock

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

Can't use @Delegate and @Shared #113

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The following doesn't work, but I can't work out why. The delegate is not null, 
but seems to be in the generated methods. 

import spock.lang.*

class SharedDelegateSpec extends Specification {

  @Shared @Delegate List things = []

  def t() {
    expect:
    things != null
    when:
    add(1)
    then:
    get(0) == 1
  }

}
​

Original issue reported on code.google.com by lda...@gmail.com on 26 Jul 2010 at 7:33

GoogleCodeExporter commented 8 years ago
What's your use case?

Original comment by pnied...@gmail.com on 28 Jul 2010 at 6:32

GoogleCodeExporter commented 8 years ago
Mixin type behaviour.

Original comment by lda...@gmail.com on 28 Jul 2010 at 11:41

GoogleCodeExporter commented 8 years ago
> Mixin type behaviour.
I get that, but can you provide a concrete example? @Shared and @Delegate are 
fundamentally incompatible, so we might have to find another way to achieve 
what you want.

Original comment by pnied...@gmail.com on 28 Jul 2010 at 11:47

GoogleCodeExporter commented 8 years ago
I need to use a mixin because I don't control the class hierarchy. It needs to 
be shared so I can use it in setupSpec() and cleanupSpec().

I worked around by moving to a stepwise test and have the first feature be just 
a given: block, which works but is a semantic stretch.

Actually, I guess I could just refer to the thing by name. Kind of lame though. 
I like magic (and ponies).

Original comment by lda...@gmail.com on 28 Jul 2010 at 11:51