Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spock GlobalExtension is not loaded (grails)

Tags:

grails

spock

geb

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?

like image 938
Moritz Avatar asked Dec 12 '13 20:12

Moritz


2 Answers

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?

like image 189
rdmueller Avatar answered Nov 18 '22 15:11

rdmueller


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.

like image 1
erdi Avatar answered Nov 18 '22 15:11

erdi