我在 Spock 规范中嘲笑 SearchableService:
// In SearchControllerSpec:
def sControl = mockFor(SearchableService)
sControl.demand.suggestQuery { Map m -> 'suggested query string' }
controller.searchableService = sControl.createMock()
被测试的代码片段如下所示:
// In SearchController:
qSuggestion = searchableService.suggestQuery( query , allowSame:false)
// FAILS:
assert qSuggestion == 'suggested query string'
highlightedSuggestion = StringQueryUtils.highlightTermDiffs(query, qSuggestion)
断言失败 - 显然是因为它qSuggestion
持有一个闭包而不是定义的字符串。
最后的语句失败,因为 highlightTermDiffs 期望 (String, String),但正在获取 (String, Closure)。
这里有什么问题?我该如何纠正错误?