In my Grails app, I want to prevent the Searchable plugin from loading when running my unit tests. I tried doing this using the following code in the Bootstrap class
def grailsApplication
def init = {servletContext ->
def currentEnv = grails.util.Environment.current.name
if (currentEnv == 'test') {
def doNothing = {println "Searchable is disabled"}
// This returns null!
def searchablePluginClass = grailsApplication.getClassForName("SearchableGrailsPlugin")
searchablePluginClass.metaClass.doWithDynamicMethods = doNothing
searchablePluginClass.metaClass.doWithSpring = doNothing
searchablePluginClass.metaClass.doWithApplicationContext = doNothing
}
}
However this doesn't work because grailsApplication.getClassForName("SearchableGrailsPlugin")
returns null, presumably because this class isn't on the classpath when this code runs. Is there any other way that I can disable this plugin?