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