Description
The attached readonlyproperty.zip contains the following:
src/main/groovy/demo/SomeTrait.groovy
package demo trait SomeTrait { String title }
src/test/groovy/demo/SomeTraitSpec.groovy
package demo import spock.lang.Specification class SomeTraitSpec extends Specification { void 'test property access'() { given: Widget.metaClass.getTitle = { 'Some Default Title' } def w = new Widget() when: w.title = 'Some New Title' then: w.title == 'Some Default Title' } } class Widget implements SomeTrait {}
That test will fail with the following:
groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: title for class: demo.Widget at demo.SomeTraitSpec.test property access(SomeTraitSpec.groovy:15)
If the trait is removed from the equation and the title property is declared directly in the Widget class then the test passes.
Attachments
Attachments
Issue Links
- is related to
-
GROOVY-7308 Change In MetaClass Behavior
- Closed