我相信现在在斯波克不可能像你期望的那样优雅。我只想到了如下几点:
def args = [arg1, arg2]
2 * service.processInput({ it == args.removeAt(0) }) >>> [out1, out2]
不确定它是否符合你的期望。下面是测试这种方法的完整规范
class SOSpec extends Specification {
def "mock a method different arguments and different return values"() {
when:
def arg1 = "F"
def arg2 = "B"
def out1 = "Foo"
def out2 = "Bar"
def service = Mock(SomeService) {
def args = [arg1, arg2]
2 * processInput({ it == args.removeAt(0) }) >>> [out1, out2]
}
then:
service.processInput(arg1) == out1
service.processInput(arg2) == out2
}
}