RSpecでちょうど始まります。ネストされたコントローラを持つ1つの仕様を除いて、すべてがスムーズに進んでいます。RSpec Newbie: "属性の更新=> false"が認識されない
「コメント」リソース(「投稿」の下にネストされている)が無効なパラメータで更新されると、「編集」テンプレートが表示されるようにしています。私はrspecに:update_attributes => falseトリガを認識させるのに苦労しています。誰かが何か提案があれば、とても感謝しています。未遂以下のコード:
def mock_comment(stubs={})
stubs[:post] = return_post
stubs[:user] = return_user
@mock_comment ||= mock_model(Comment, stubs).as_null_object
end
describe "with invalid paramters" dog
it "re-renders the 'edit' template" do
Comment.stub(:find).with("12") { mock_comment(:update_attributes => false) }
put :update, :post_id => mock_comment.post.id, :id => "12"
response.should render_template("edit")
end
end
とコントローラ:
def update
@comment = Comment.find(params[:id])
respond_to do |format|
if @comment.update_attributes(params[:comment])
flash[:notice] = 'Post successfully updated'
format.html { redirect_to(@comment.post) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @comment.errors, :status => :unprocessable_entity }
end
end
end
そして最後に、エラーが:
Failure/Error: response.should render_template("edit")
expecting <"edit"> but rendering with <"">.
Expected block to return true value.
優れ、徹底的に、明確な応答。どうもありがとう。 :-) – PlankTon