I want to register a Listener to all spock geb specs in my grails-app so I added a IGlobalExtension to myapp/src/groovy
package myapp.spock
class TakeScreenshotExtension implements IGlobalExtension {
@Override
void visitSpec(SpecInfo specInfo) {
System.err.println "ADDING LISTENER"
specInfo.addListener(new TakeScreenshotOnFailureListener())
}
}
Afterwards I added the org.spockframework.runtime.extension.IGlobalExtension file to myapp/src/resources/META-INF/services containing the line
myapp.spock.TakeScreenshotExtension
So now from what I understood, when running grails test-app functional:, the Extension should be loaded but I don't see the "ADDING LISTENER" anywhere in the output. What am I doing wrong?
the right location for the IGlobalExtension
file seems to be
grails-app/conf/META-INF/services
, but then I get a class not found Exception
because spock can't load my extension class. Any Idea where I have to put that?
I'm not sure what is the exact classpath setup when running functional tests but I would suspect that myapp/src/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension
might not get added to the test classpath and thus Spock doesn't know about your extension. I would try moving that file under myapp/test/functional/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension
together moving the extension class under myapp/test/functional
as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With