Spock - 提取交互方法 [英] Spock - extracting interactions to method

查看:87
本文介绍了Spock - 提取交互方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

spock文档指出,您可以将然后块的断言提取到其他方法并在之前添加 assert 关键字每个断言。



我也想将互动提取到辅助方法
我尝试了与交互闭包交互的包装交互,但这种方式无效。

可能吗?如果是它如何实现的话?

解决方案

原来你可以。您必须用交互包装辅助方法调用:

 然后:
交互{
helperMethod()

然后您可以将交互放置在这样的辅助方法中:

  def helperMethod(){
1 * someObj.getInt()>> 2
}

我以其他方式做了它(包装的帮助方法body in interaction),这就是为什么它不能正常工作


The spock documentation points out that you can extract assertions of then block to other method and add assert keyword before each assertion.

I would also like to extract interactions to helper method. I tried wrapping interactions with interaction closure block but that did not work.

Is it possible? If it is how to achieve it?

解决方案

Turns out you can. You have to wrap helper method call with interaction:

then:
    interaction {
         helperMethod()
    }

and then you can put interactions in a helper method like that:

def helperMethod() {
    1 * someObj.getInt() >> 2
}

I did it other way around (wrapped helper method body in interaction), that's why it did not work

这篇关于Spock - 提取交互方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆