使用 expects().twice.with().returns 使用 Mocha,Rails

Using expects().twice.with().returns using Mocha, Rails

我正在使用 mocha 来模拟我的测试。

这是我正在尝试做的一个例子。

ClassName.expects(:method_name).twice.with() do |options|
  options == input_options1 || options == input_options2
end.returns("abc123", "def456")

以上作品。

但是还有另一种方法吗,我可以在 input_options 上指定两种不同的类型,比如

ClassName.expects(:method_name).twice.with(input_options1,input_options2).returns("abc123", "def456")

我的函数 "method_name" 只接受一个参数。

尝试关注。

ClassName.expects(:method_name).twice.with(any_parameters).returns("abc123", "def456")

不,没有。您必须适应您提出的第一个解决方案。

你可以这样做:

ClassName.expects(:method_name).with(input_options1).returns("abc123")
ClassName.expects(:method_name).with(input_options2).returns("def456")