Rspec 从存根中排除某些参数
如果我想删除一个用户实例“has_law”?我所做的方法可以做到这一点:Rspec 从存根中排除某些参数,rspec,Rspec,如果我想删除一个用户实例“has_law”?我所做的方法可以做到这一点: allow(user).to receive(:has_law?).with(anything).and_return(true) 无论将什么参数传递给has_law?,这都将返回true 但是,如果我想给它任何论点,除了说:foo,我该怎么办 我该怎么做 伪代码: allow(user).to receive(:has_law?).with(anything_except(:foo)).and_return(true)
allow(user).to receive(:has_law?).with(anything).and_return(true)
无论将什么参数传递给has_law?,这都将返回true
但是,如果我想给它任何论点,除了说:foo,我该怎么办
我该怎么做
伪代码:
allow(user).to receive(:has_law?).with(anything_except(:foo)).and_return(true)
#=> undefined method `anything_except'
您可以编写自己的matcher或使用以下未经测试的工具:
allow(user).to receive(:has_law?) do |arg|
expect(arg).not_to eq(:foo)
true
end