Reputation: 65
Given this mapping:
"/student/degree/$studentid/$degreecode"(controller:'student', action:'degree')
I am trying the tests below and both fail with AssertionFailedError: '...did not match any mapping'
and both are valid URLs that do function. I can succeed with a test URL of just '/student/degree' which I think should fail as the parameters are required.
It seems the assertURL
methods are not handling multiple parameters. Does this only work for 'id' and is it not possible to create tests for these URLs?
@TestFor(UrlMappings)
@Mock([StudentController])
class UrlMappingsTests {
void testUrlMappings() {
assertForwardUrlMapping("/student/degree/102345678/N", controller: "student", action: "degree") {
assertForwardUrlMapping("/student/degree/102345678/N", controller: "student", action: "degree") {
studentid = 102345678
degreecode = "N"
}
}
}
}
Upvotes: 0
Views: 496
Reputation:
Tested with Grails 2.2.4, and it works for me, I just add a custom mappings class:
package test
class MyUrlMappings {
static mappings = {
"/test/show/$myId/$myVal"(controller: "test", action: "show")
}
}
import spock.lang.*
import test.MyUrlMappings
@TestFor(MyUrlMappings)
@Mock([TestController])
//I'm using Spock
class MyUrlMappingsSpec extends Specification {
void "mapping should consider myId and myVal"() {
expect:
assertForwardUrlMapping("/test/show/1/tst", controller: "test", action: "show") {
//all params considered as String
myId = '1'
myVal = 'tst'
}
}
}
Upvotes: 1