从存根中排除某些参数

时间:2014-09-14 15:05:42

标签: rspec

如果我想要删除用户实例'has_law?方法,我可以这样做:

allow(user).to receive(:has_law?).with(anything).and_return(true)

无论传递给true的参数是什么,都会返回has_law?

但如果我想从AP :foo提出任何论据,我该怎么办?

我该怎么做?

伪代码:

allow(user).to receive(:has_law?).with(anything_except(:foo)).and_return(true)
#=> undefined method `anything_except'

1 个答案:

答案 0 :(得分:0)

您可以编写自己的匹配器或使用以下(未经测试):

allow(user).to receive(:has_law?) do |arg|
  expect(arg).not_to eq(:foo)
  true
end