Skip to content

Instantly share code, notes, and snippets.

@ishults
Created February 21, 2016 18:05
Show Gist options
  • Save ishults/594a1d9a266fbb645d8d to your computer and use it in GitHub Desktop.
Save ishults/594a1d9a266fbb645d8d to your computer and use it in GitHub Desktop.
The working filter unit tests
@Mock(UriFilters)
@TestFor(MyController)// Need a controller to test filters
class UriFiltersSpec extends Specification {
void "myFilter() should set the names of the controller and action"() {
setup:
request.requestURI = '/some/path/here'
when:
withFilters(controller: 'my', action: 'index') { controller.index() }
then:
response.getHeader('controllerName') == 'my'
response.getHeader('actionName') == 'index'
response.contentAsString == 'success'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment