|
I want to migrate a Grails 1.3 application to Grails 2.x. In our tests we use a lot of mixins. The code below works correctly in Grails 1.3 and Grails 2.0 without any specific Grails 2.0 test mixin: @Category(Specification) class AGroovyMixin { def methodInMixinThatInvokesMethodOfSpec() { println 'the method in the mixin is called' methodOfSpecInvokedInMixin() } } @Mixin(AGroovyMixin) class FirstSpec extends Specification { def invocations = 0 def methodOfSpecInvokedInMixin() { invocations++ } def 'check that that a method of this spec has been called in the mixin'() { when: methodInMixinThatInvokesMethodOfSpec() then: invocations > 0 } } In Grails 2.0, if I want to mix Grails test mixins (@Mock, @TestMixin) with our own categories, my category is not mixed into the test class. It means, you cannot use @Mock or @TestMixin with the vanilla @Mixin. Alternatively, if I try to mix in my category using the @TestMixin, the category has no access to the test class code (see the example below).
// SECOND EXAMPLE - est fails class AGrailsTestMixin { def methodInMixinThatInvokesMethodOfSpec() { println 'the method in the mixin is called' methodOfSpecInvokedInMixin() } } @TestMixin(AGrailsTestMixin) class SecondSpec extends Specification { def invocations = 0 def methodOfSpecInvokedInMixin() { invocations++ } def 'check that that a method of this spec has been called in the test mixin'() { when: methodInMixinThatInvokesMethodOfSpec() then: invocations > 0 } } I would like to combine @Mixin with @Mock, or have an implementation of @TestMixin that can access methods on the target class. What could I do? Cheers, Marcin |
|
> I would like to combine @Mixin with @Mock, or have an implementation of
> @TestMixin that can access methods on the target class. What could I do? This is really a question for the user mailing list although it probably makes sense to discuss potential solutions here because it may require changes to Grails. Or maybe Groovy. Does anyone know why @Mixin doesn't play nice with the new test annotations? -- Peter Ledbrook Developer Advocate VMware t: @pledbrook --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
This post has NOT been accepted by the mailing list yet.
|
|
Administrator
|
In reply to this post by pledbrook
The metaclass is cleaned up after each run which removes the mixin methods, you have to reapply the mixin with MyClass.metaClass.mixin MyMixin in the setup of the method
Cheers On Wed, Nov 14, 2012 at 9:15 AM, Peter Ledbrook <[hidden email]> wrote:
Graeme Rocher Grails Project Lead SpringSource - A Division of VMware http://www.springsource.com |
|
I'll try the solution proposed by Graeme.
Marcin Gryszko ![]() On Wed, Nov 14, 2012 at 4:52 PM, Graeme Rocher <[hidden email]> wrote: The metaclass is cleaned up after each run which removes the mixin methods, you have to reapply the mixin with MyClass.metaClass.mixin MyMixin in the setup of the method |
|
Can this be changed in Grails? It is absolutely mind-boggling (even though the answer is simple).
On 14 November 2012 21:11, Marcin Gryszko <[hidden email]> wrote: I'll try the solution proposed by Graeme. ________________________________ ꜽ . antony jones . http://www.enzy.org |
|
In reply to this post by Graeme Rocher-4
Tested the Graeme's hint and it works.
I agree with Antony that Grails mixins should be compatible with Groovy mixins. Should I file a JIRA issue for this? Marcin Gryszko ![]() On Wed, Nov 14, 2012 at 4:52 PM, Graeme Rocher <[hidden email]> wrote: The metaclass is cleaned up after each run which removes the mixin methods, you have to reapply the mixin with MyClass.metaClass.mixin MyMixin in the setup of the method |
| Powered by Nabble | Edit this page |
