在 Spockframework 1.3 中,以下适用于间谍
instance = (MyClass) Spy(
MyClass,
constructorArgs: [env, steps])
类将环境和步骤存储为 this.env, this.steps
在 2.0 中,当任何内容引用时,该步骤就会失败,并出现以下错误:
No signature of method: MyClass.getSteps()
is applicable for argument types: () values: []
该错误似乎仅在 Spy 对象访问闭包内的构造函数创建字段时才会发生
// OK
steps.method()
// Failure
c = { steps.method() }
c()
好吧,事情是这样的
当我们运行闭包时,它会设置一个委托来控制它如何处理闭包中未定义的方法调用/道具。
this.steps 通过委托变成 this.getSteps() 。 一种选择是使用闭包将
def getSteps() { return steps}
添加到类中。
这可行,但似乎是错误的