9

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?

Moritz
  • 489
  • 1
  • 5
  • 18

2 Answers2

2

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?

rdmueller
  • 10,742
  • 10
  • 69
  • 126
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.

erdi
  • 6,944
  • 18
  • 28
  • 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 suggestions – user1511808 Jan 12 '23 at 01:47