In Spockframework 1.3 the following works for spy
instance = (MyClass) Spy( MyClass, constructorArgs: [env, steps])
Class stores env and steps as this.env, this.steps. It does not define getEnv() or getSteps()
class BaseClass { def env def steps BaseClass(def env, def steps) { this.env = env this.steps = steps }}class MyClass extends BaseClass { MyClass(def env, def steps) { super(env, steps) }}
In 2.0 this fails when anything references the steps fails with errors like:
No signature of method: MyClass.getSteps() is applicable for argument types: () values: []
The error only seems to happen when, within a closure, the Spy object attempts access of a field updated by the constructor.
// OKsteps.method()// Failurec = { steps.method() }c()
Talking with copilot it seems that the issue is with the closure delegate and I can fix this a few ways
- implement getters for fields ( add
def getSteps() { return steps }
) - set delegate to
this
c = { steps.method() }c.delegate = thisc.() // ok
I haven't yet looked at before after to check what class is delegate in Spy case for spock 1.3 v 2.0. I'll update this question after I do so