Spock GlobalExtension is not loaded (grails)
Asked Answered
G

2

10

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?

Guardado answered 12/12, 2013 at 20:35 Comment(2)
shouldn't it be System.err.println("ADDING LISTENER") ?Elemental
in Java, you need the braces, in Groovy, you don't...Pilot
P
3

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?

Pilot answered 17/11, 2014 at 21:33 Comment(0)
H
1

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.

Heighho answered 14/12, 2013 at 13:6 Comment(1)
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. --> I tried this but this didnt work any inputs or suggestionsKiele

© 2022 - 2024 — McMap. All rights reserved.