[
https://issues.apache.org/jira/browse/GROOVY-5489?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles closed GROOVY-5489.
-------------------------------
Resolution: Information Provided
> Problem with closure delegate and invokeMethod
> ----------------------------------------------
>
> Key: GROOVY-5489
> URL: https://issues.apache.org/jira/browse/GROOVY-5489
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 2.0-rc-1, 2.4.0-rc-1
> Reporter: Jeff Brown
> Priority: Major
> Attachments: delegatequestion.zip
>
>
> I am not sure if this is a bug or an intended change.
> The following test passes with 1.8.6 but does not with 2.0.0-rc-1. With rc-1
> the call to doSomething() throws MethodMissingException.
> {code:title=src/test/groovy/com/demo/ClosureSpec.groovy|borderStyle=solid}
> package com.demo
> import spock.lang.Specification
> class ClosureSpec extends Specification {
> void 'Test invokeMethod on delegate'() {
> given:
> def value
> def closure = {
> doSomething(42)
> }
> def handler = { String name, args ->
> value = args[0]
> }
> closure.delegate = [invokeMethod: handler] as GroovyObjectSupport
> when:
> closure()
> then:
> value == 42
> }
> }
> {code}
> I have attached a zip file with a small project which includes that test. To
> run the test:
> {noformat}
> ./gradlew test
> {noformat}
> At the top of the project is a build.gradle file:
> {code:title=build.gradle|borderStyle=solid}
> apply plugin: 'groovy'
> repositories {
> maven { url 'http://repo.grails.org/grails/core' }
> maven { url 'http://oss.sonatype.org/content/repositories/snapshots' }
> }
> dependencies {
> // the test passes with these values...
> def groovyVersion = '1.8.6'
> def spockVersion = '0.6-groovy-1.8-SNAPSHOT'
> // the test fails with these values...
> // def groovyVersion = '2.0.0-rc-1'
> // def spockVersion = '0.7-groovy-2.0-SNAPSHOT'
> groovy group: 'org.codehaus.groovy', name: 'groovy', version:
> groovyVersion
> testCompile group: 'org.spockframework', name: 'spock-core', version:
> spockVersion
> }
> {code}
> Change the versions as specified in the comments to see the problem.
> Is this an intentional change?
> We have code that does something very much like this in Grails. If this
> change in behavior is intentional, how might we achieve the same kind of
> behavior in 2.0?
--
This message was sent by Atlassian Jira
(v8.20.1#820001)