5
我試圖從使用respond_to切換到Rails控制器的respond_with。一切都很順利,除了測試控制器規格中的無效保存外。這裏有一個例子:Rails的respond_with&Rspec控制器:測試不成功的更新
形容做myController的...
describe "PUT update" do
context "with invalid attributes" do
it "should re-render the edit page" do
style = stub_model(Style)
Style.stub(:find) { style }
Style.any_instance.stub(:save).and_return(false)
put :update
response.should render_template(:edit)
end
end
end
end
這工作只是我的舊的respond_to款式更新動作不錯,但與respond_with,我得到
Failure/Error: response.should render_template("edit")
所以,總之 - 我如何測試這個? ...或者我應該假設render_with知道它在做什麼,而不是測試呢?任何一般建議?
乾杯提前
PS:更新動作:
def update
@style = Style.find(params[:id])
flash[:notice] = "Style updated" if @style.update_attributes(params[:style])
respond_with(@style)
end