0

我在 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)。

这里有什么问题?我该如何纠正错误?

4

1 回答 1

4

你在打电话suggestQuery(String, Map),但你在嘲笑suggestQuery(Map)。尝试

sControl.demand.suggestQuery { String query, Map m -> 'suggested query string' }
于 2011-10-04T17:51:54.080 回答