Issue
I was trying to assert the values inside "render" in my unit test cases written in Grails. But it does not seems to be proper
render(view:"create",model[:])
what i tried was assertEquals("create",renderArgs("view"))
i also tried some alternatives like controller.response.renderedUrl etc. But none of those are working. Could someone give an idea?
Thanks in advance, BK
Solution
The following tests work:
grails-app/controllers/demo/DemoController.groovy:
package demo
class DemoController {
def index() {
render view: 'first'
}
}
test/unit/demo/DemoControllerSpec.groovy:
package demo
import grails.test.mixin.TestFor
import spock.lang.Specification
@TestFor(DemoController)
class DemoControllerSpec extends Specification {
void "test render view"() {
when:
controller.index()
then:
'/demo/first' == view
}
}
test/unit/demo/DemoControllerTests.groovy:
package demo
import grails.test.mixin.TestFor
@TestFor(DemoController)
class DemoControllerTests {
void testRenderView() {
controller.index()
assert '/demo/first' == view
}
}
I hope that helps.
Answered By - Jeff Scott Brown