如何使用 RSpec should_receive 期待一些(但不是全部)参数? [英] How to expect some (but not all) arguments with RSpec should_receive?
本文介绍了如何使用 RSpec should_receive 期待一些(但不是全部)参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Foo
def bar(a, b)
...
Foo.should_receive( :bar )
期望使用任何参数调用 bar.
expects bar to be called with any arguments.
Foo.should_receive( :bar ).with( :baz, :qux )
期望 :baz 和 :qux 作为参数传入.
expects :baz and :qux to be passed in as the params.
如何期望第一个参数等于 :baz,而不关心其他参数?
How to expect the first param to equal :baz, and not care about the other params?
推荐答案
使用 anything
匹配器:
Foo.should_receive(:bar).with(:baz, anything)
这篇关于如何使用 RSpec should_receive 期待一些(但不是全部)参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文