0

我尝试在控制器中添加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")

规范通过。为什么?

4

1 回答 1

5

很合乎逻辑。

当你这样做时:

answer.should_receive(:update_attributes).with("content" => "Changed content")

update_attributes没有被解雇。

您可以使用and_call_original触发该方法。见文档

于 2013-03-20T13:35:47.417 回答