如何在 Rspec 中添加 results.map(&:blank_image)?
How do I stub a results.map(&:blank_image) in Rspec?
我正在编写测试,我遇到了这一行:
blank_images = results.map(&:blank_image)
在我的测试中,我试图对它进行存根并将其 return 一个数组:
expect(results).to receive(:map).with(&:blank_image).and_return([true, true, true])
我不断收到消息:
ArgumentError: `with` must have at least one argument. Use `no_args` matcher to set the expectation of receiving no arguments.
如何将 &:blank_image
传递给 Rspec 中的 with()
方法?
**编辑:另外,&:blank_image
的搜索词是什么,这样我就可以了解更多这意味着什么。
我认为你可以使用:
expect(results).to receive(:map). and_yield(a_object_with_blank_image_property). and_yield(aother_object_with_blank_image_property)
参考:https://makandracards.com/makandra/1321-rspec-stubbing-a-method-that-takes-a-block
我正在编写测试,我遇到了这一行:
blank_images = results.map(&:blank_image)
在我的测试中,我试图对它进行存根并将其 return 一个数组:
expect(results).to receive(:map).with(&:blank_image).and_return([true, true, true])
我不断收到消息:
ArgumentError: `with` must have at least one argument. Use `no_args` matcher to set the expectation of receiving no arguments.
如何将 &:blank_image
传递给 Rspec 中的 with()
方法?
**编辑:另外,&:blank_image
的搜索词是什么,这样我就可以了解更多这意味着什么。
我认为你可以使用:
expect(results).to receive(:map). and_yield(a_object_with_blank_image_property). and_yield(aother_object_with_blank_image_property)
参考:https://makandracards.com/makandra/1321-rspec-stubbing-a-method-that-takes-a-block