spock
spock copied to clipboard
Using GroovySpy on class with propertyMissing() results in unexpected MissingMethodException
Describe the bug
when using GroovySpy() with an obkject that has propertyMissing() implemented, attempts to access dynamic properties results in an exception
To Reproduce
package example
import spock.lang.Specification
class TestClass {
def propertyMissing(String name) {
return name
}
}
class TesterSpec extends Specification {
def 'No Spy'() {
given: 'an instance'
TestClass sut = new TestClass()
expect: 'property to be returned'
sut.bob == 'bob'
}
// This does not work
def 'Spy'() {
given: 'a spied instance'
TestClass sut = GroovySpy()
expect: 'property to be returned'
sut.bob == 'bob'
}
}
Expected behavior
Both test should pass
Actual behavior
second test fails with
ondition failed with Exception:
sut.bob == 'bob'
| |
| groovy.lang.MissingMethodException: No signature of method: example.TestClass.getBob() is applicable for argument types: () values: []
| Possible solutions: getAt(java.lang.String), getClass(), notify(), every(), grep()
| at example.TesterSpec.Spy(TesterSpec.groovy:27)
example.TestClass$$EnhancerByCGLIB$$9a1d9323@7e0f56d8
Java version
Corretto-11
Buildtool version
------------------------------------------------------------
Gradle 6.7
------------------------------------------------------------
Build time: 2020-10-14 16:13:12 UTC
Revision: 312ba9e0f4f8a02d01854d1ed743b79ed996dfd3
Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 11.0.14.1 (Amazon.com Inc. 11.0.14.1+10-LTS)
OS: Mac OS X 13.6 x86_64
What operating system are you using
Mac
Dependencies
Using Spock 1.3-groovy-2.4 with Groovy 2.4.12
Additional context
This is in a very specific setup, so on old version of spock/Groovy but I am told it is recreatable with latest version