Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.4.3
-
None
-
None
Description
The attached privatemethods.zip contains the following:
src/main/groovy/demo/Widget.groovy
package demo class Widget { def somePublicMethod() { 'real value' } private somePrivateMethod() { 'real value' } }
src/test/groovy/demo/WidgetSpec.groovy
package demo import spock.lang.Specification class WidgetSpec extends Specification { void 'test meta methods'() { when: 'a public method is replaced at runtime' Widget.metaClass.somePublicMethod = { -> 'test value' } then: 'the meta method is used' 'test value' == new Widget().somePublicMethod() when: 'a private method is replaced at runtime' Widget.metaClass.somePrivateMethod = { -> 'test value' } then: 'the meta method is used' // This one passes with Groovy 2.3.11 and fails with 2.4.3 'test value' == new Widget().somePrivateMethod() } }
build.gradle
apply plugin: 'groovy' repositories { jcenter() } dependencies { boolean useGroovy24 = true if(useGroovy24) { compile 'org.codehaus.groovy:groovy-all:2.4.3' compile 'org.spockframework:spock-core:1.0-groovy-2.4' } else { compile 'org.codehaus.groovy:groovy-all:2.3.11' compile 'org.spockframework:spock-core:1.0-groovy-2.3' } }
The tests can be run with the following:
./gradlew test
Is the change in behavior with respect to private methods here intentional?