有一些控制器:
def index() {
...
render(view: 'index', model: [exceptions: exceptions]
}
还有单元测试:
def testIndex(){
...
controller.index()
assert controller.response.status == 200
assert controller.response.contentAsString != ""
}
第二个断言失败,contentAsString
返回“”。当我render()
用render("html")
-替换时,contentAsString
即使在测试中也能满足。我做错了什么?
更新 1
索引.gsp
<%@ page contentType="text/html"%>
<%@ page import="org.apache.commons.lang.exception.ExceptionUtils" %>
<html>
<head>
<title>Exceptions catched during crawling</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".stacktrace").hide()
$("a").click(function(){
$(this).parents("li").siblings("pre").toggle()
return false;
})
})
</script>
</head>
<body>
<g:each var="entry" in="${exceptions.entrySet()}">
Catched <b>${entry.key.name}</b> for these URLs:
<ol>
<g:each var="ex" in="${entry.value.entrySet()}">
<li><a href="${ex.key}">${ex.key}</a>: ${ex.value.message}</li>
<pre class="stacktrace">
${ExceptionUtils.getStackTrace(ex.value)}
</pre>
</g:each>
</ol>
</g:each>
</body>
</html>
更新 2 从 grails 2.2.3 升级到 grails 2.2.4 没有帮助 ;(