RSpec으로 시작하기. 중첩 된 컨트롤러가있는 하나의 사양을 제외하면 모든 것이 원활하게 진행됩니다.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