You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Ronny Løvtangen (JIRA)" <ji...@apache.org> on 2015/09/11 12:06:46 UTC

[jira] [Commented] (GROOVY-7368) Change In Behavior For MetaMethods Replacing Private Methods

    [ https://issues.apache.org/jira/browse/GROOVY-7368?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14740515#comment-14740515 ] 

Ronny Løvtangen commented on GROOVY-7368:
-----------------------------------------

Hope this is not intentional.

> Change In Behavior For MetaMethods Replacing Private Methods
> ------------------------------------------------------------
>
>                 Key: GROOVY-7368
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7368
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.3
>            Reporter: Jeff Brown
>         Attachments: privatemethods.zip
>
>
> The attached privatemethods.zip contains the following:
> {code:borderStyle=solid|title=src/main/groovy/demo/Widget.groovy}
> package demo
> class Widget {
>     def somePublicMethod() {
>         'real value'
>     }
>     private somePrivateMethod() {
>         'real value'
>     }
> }
> {code}
> {code:borderStyle=solid|title=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()
>     }
> }
> {code}
> {code:borderStyle=solid|title=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'
>     }
> }
> {code}
> The tests can be run with the following:
> {noformat}
> ./gradlew test
> {noformat}
> Is the change in behavior with respect to private methods here intentional?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)