Skip to content

Instantly share code, notes, and snippets.

@ddelponte
Created September 17, 2014 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddelponte/80f582979b44687d39da to your computer and use it in GitHub Desktop.
Save ddelponte/80f582979b44687d39da to your computer and use it in GitHub Desktop.
How to test REST UrlMappings
import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import spock.lang.IgnoreRest
import spock.lang.Specification
import spock.lang.Unroll
@Unroll
@TestFor(UrlMappings)
@Mock([MockYourController])
class UrlMappingsSpec extends Specification {
def "Ensure basic mapping operations"() {
expect:
assertForwardUrlMapping(url, controller: expectCtrl, action: expectAction) {
someId = expectId
}
where:
url | expectCtrl | expectAction | expectId
'/blah/123/blah/blah' | 'myController' | 'myAction' | '123'
}
def "Verify REST endpoint for url #url and request method #requestMethod is properly resolved"() {
given:
webRequest.currentRequest.method = requestMethod
expect:
assertForwardUrlMapping(url, controller: expectCtrl, action: expectAction)
where:
url | expectCtrl | expectAction | requestMethod
"/something" | "something" | "show" | "GET"
"/something/1" | "something" | "show" | "GET"
"/something" | "something" | "save" | "POST"
"/something" | "something" | "update" | "PUT"
"/something" | "something" | "delete" | "DELETE"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment