我正在针对rspec编写测试,并且需要允许以下行用于Location模型:
Location.where(id: params[:id]).first
但这是不正确的(两个参数而不是一个错误):
allow(Location).to receive(:where, :first).with(id: my_id)
这是这样的:
allow(Location).to receive(:where).with(id: my_id).first
哪种方法是正确的?
因为它是您可以做的:
allow(Location).to receive(:where).with(id: my_id).and_return double(first: <your Location mock here>)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句