Is there a way to test this interceptor? It’s being ignored in my test.
Code:
class BaseDomainController {
def beforeInterceptor = {
throw new RuntimeException()
if(!isAdmin()){
redirect(controller: 'login', action: 'show')
return
}
}
}
class BaseDomainControllerSpec extends IntegrationSpec{
BaseDomainController controller = new BaseDomainController()
def 'some test'(){
given:
controller.index()
expect:
thrown(RuntimeException)
}
}
According to this thread http://grails.1312388.n4.nabble.com/Controller-interceptors-and-unit-tests-td1326852.html Graeme indicates you have to call the interceptor separately. In our case, since we are using the interceptor to check a token, and it’s the same for every action, we used:
I guess if each unit test specifies different arguments for the interceptor, you’ll have to call it separately each time. If don’t want to to this, I think you have to use something like the Grail’s functional testing, which will go through the entire lifecycle: http://grails.org/plugin/functional-test