我正在编写测试,我接受了这一行:
blank_images = results.map(&:blank_image)
在我的测试中,我试图将其存根并让它返回一个数组:
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
的搜索字词是什么,以便我可以详细了解这意味着什么。
答案 0 :(得分:0)
我认为你可以使用:
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