Reputation: 483
I'm new for grails
and I've been trying some tutorial but it's not working. I want to
pass value to the view but it's empty. My code is as following:
Controller:
package grail.test.project
import grails.test.mixin.TestFor
import spock.lang.Specification
@TestFor(HelloController)
class HelloControllerSpec extends Specification {
def index() {
render(model:[name : "JOHNY"])
}
}
View (views/hello/index.jsp)
<!DOCTYPE html>
<html>
<head>
<meta name="layout" content="main"/>
<title>Welcome to Grails</title>
</head>
<body>
Hello World !!! This is grails application for testing project with text.
<br>
Parameter from controller: ${name}
</body>
</html>
It's not print the name that send from controller. I might miss something, please help thank you.
Upvotes: 0
Views: 188
Reputation: 1062
You are using render method in test case that is not possible. Please create your controller like .
class HelloController {
def index() {
render(view:'index',model:[name : "JOHNY"])
}
}
Upvotes: 0
Reputation: 91
As I saw, you have problem in syntax for render(), either you have to write
render(view:'index',model:[name : "JOHNY"])
or just
[name:"JOHNY"]
Upvotes: 1