我尝试将assigns
添加到控制器
update
操作规范中
it "update the content" do
Answer.should_receive(:find).with(answer.id.to_s).and_return(answer)
answer.should_receive(:update_attributes).with("content" => "Changed content")
put :update, id: answer.id, app_id: app.id, answer: {content: "Changed content"}
assigns(:answer).content.should eq('Changed content') # explicitly permitted
response.status.should eq 406
end
但我收到错误:
Failure/Error: assigns(:answer).content.should eq('Changed content') # explicitly permitted
expected: "Changed content"
got: "base content"
(compared using ==)
但是当我评论时:
#answer.should_receive(:update_attributes).with("content" => "Changed content")
规格通过。为什么呢?
答案 0 :(得分:5)
很合乎逻辑。
当你这样做时:
answer.should_receive(:update_attributes).with("content" => "Changed content")
update_attributes
未被解雇。
您可以使用and_call_original
来触发该方法。 See doc