0
import grails.plugin.spock.*
class EventControllerSpec extends ControllerSpec {
def "Creating a breadcrumb from an event"() {
given: "I have a named event"
def eventController = Mock(EventController)
def event = Mock(Event)
event.title >> 'Space-Journey with Sprock and the Crew'
event.title == 'Space-Journey with Sprock and the Crew'
when: "I create a breadcrumb from it"
def eventCrumb = eventController.createCrumb("Event", "show", "1", event.title)
/*
private Map createCrumb (String controllerName, String actionName, String id, String msg) {
msg = (msg ? msg : "cr.breadcrumb.${controllerName}.${actionName}")
[ 'controller':controllerName,
'action':actionName,
'id':id,
'message':msg
]
*/
then: "I receive a map where the message-value is the events' title"
eventCrumb.message == event.title
}
}
注意注释掉的方法是在EventController即使使用Spock的Mock()模拟底层控制器,该方法为什么返回null?
- 为什么片断原因“不能空对象上获取属性‘消息’”?
- 如何正确设置代码片段?
- 一般情况下,会/不会,我需要的任何mockTagLib,mockController,mockLogging GrailsUnitTestCase功能使用斯波克什么时候?
太好了!谢谢,mfloryan。 在这种情况下(?),它是控制器的元类吗? – user569825 2011-01-13 11:14:21