我在寫一篇RSpec的測試,並需要允許選址模型以下行:RSpec的允許在那裏(ID:添加my_id)。首先
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
這將是這樣做的正確方法?
如果將代碼更改爲'Location.find_by(id:params [:id])' – BroiSatse