刚开始使用RSpec。除了嵌套控制器的一个规格外,一切都很顺利。RSpec新手:“更新属性=> false”未被识别
我试图确保当'comment'资源(嵌套在'post'下)用无效参数更新时,它会呈现'edit'模板。我努力让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 2011-01-14 21:47:23