|
|
This post has NOT been accepted by the mailing list yet.
Hi,
I have a code like this that works right with groovy mixins:
import spock.lang.Specification
// FIRST EXAMPLE - The test passes
@Category(GroovyObject)
class AGroovyMixin {
def methodInTheMixinThatInvokesAMethodOfTheSpec() {
println 'the method in the mixin is called'
aMethodOfTheSpecInvokedInAMixin()
}
}
@Mixin(AGroovyMixin)
class FirstSpec extends Specification {
def invocations = 0
def aMethodOfTheSpecInvokedInAMixin() {
invocations++
}
def 'check that that a method of this spec has been called in the mixin'() {
when:
methodInTheMixinThatInvokesAMethodOfTheSpec()
then:
invocations > 0
}
}
but when I use '@Mock' or '@TestMixin' in my FirstSpec, my own groovy mixin (AGroovyMixin) stop work.
If I change the code to use a @TestMixin implementation, the test fails.
import spock.lang.Specification
import grails.test.mixin.TestMixin
// SECOND EXAMPLE - The test fails
class AGrailsTestMixin {
def methodInTheMixinThatInvokesAMethodOfTheSpec() {
println 'the method in the mixin is called'
aMethodOfTheSpecInvokedInAMixin()
}
}
@TestMixin(AGrailsTestMixin)
class SecondSpec extends Specification {
def invocations = 0
def aMethodOfTheSpecInvokedInAMixin() {
invocations++
}
def 'check that that a method of this spec has been called in the test mixin'() {
when:
methodInTheMixinThatInvokesAMethodOfTheSpec()
then:
invocations > 0
}
}
I would like to combine the use of @Mixin with @Mock, or have an implementation of @TestMixin that can access to methods on the target class. What could I do?
Thanks.
David.
|