Reputation: 83
I am writing a grails plugin. At one point, there was a service which I wrote spock tests for that existed in the plugin. This all worked great, however for visibility concerns I moved the methods out of the service and directly into the GrailsPlugin
class at the root of my plugin (ultimately removing the service class).
The problem is I still want to test these methods, but I cannot seem to find a way to get access to the GrailsPlugin
class since it is not in a package and it lives at the root of my project.
I am aware that plugins like Grails Shiro use small grails applications as tests off the /test directory. However that is unnecessary for what I am trying to accomplish. In a perfect world, I would like to have a spock test for my GrailsPlugin class. Is this possible?
Upvotes: 0
Views: 44
Reputation: 2187
I haven't tried it, but maybe you can do something like the following in your Spock Specification
's setup
method to create an instance of your plugin class:
def gcl = new GroovyClassLoader()
def pluginDir = new File('.')
gcl.addClasspath(pluginDir.canonicalPath)
def pluginClass = gcl.loadClass('QuartzGrailsPlugin')
def plugin = pluginClass.newInstance()
Obviously, I took this example from the Quartz plugin. I found it here:
Upvotes: 1