Asserting view with Grails Spock Unit Test for Controllers -


  • grails 2.2.4
  • spock 0.7

i'm trying test correct view rendered grails controller. create method looks this:

def create() {     def documentcategories = documentcategory.list()     def documenttypes = documenttype.list()     def documentcomponents = documentcomponent.list()     [documentcategories: documentcategories,         documenttypes: documenttypes,         documentcomponents:documentcomponents] } 

and test:

def "test create action"() {     given:     def model = controller.create()      expect:     response.status == 200     model.documentcategories.size() == 0     model.view == '/document/create' } 

i've tried various versions of model.view including:

view == '/document/create' response.forwardedurl == '/document/create' 

all of fail because model.view, view, , response.forwardedurl null. suggestions?

as not defining view explicitly in controller method grails conventions take place. accordingly documentation view matching name of controller , method chosen --> view: "controllername/methodname"

regarding problem, should not testing grails framework working. should testing controller behaves want.

in case want test controller not specify view expected behavior of controller.

test be:

   then:     controller.modelandview == null     response.redirectedurl == null 

as modelandview created if call 'render(view: xxx)' in controller.

calling redirect() or chain() in controller results response.redirectedurl populated in unit test


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -