Rails response_with & Rspec controllers: testing failed update

I am trying to switch using response_to to response_with in Rails controllers. Everything goes smoothly, with the exception of checking for invalid saves in the controller specifications. Here is an example:

describe MyController do ...

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

This works fine with my old response_to style update action, but with response_with I get

Error / Error: response.should render_template ("edit")

So, in short - how can I check this? ... Or should I just assume that render_with knows what it does and doesn't test at all? Any general suggestions?

Greetings in advance

PS: Update action:

  def update
    @style = Style.find(params[:id])
    flash[:notice] = "Style updated" if @style.update_attributes(params[:style])
    respond_with(@style)
  end
+5
source share
1 answer

( ) - :

Location.any_instance.stub(:valid?).and_return(false)
Location.any_instance.stub(:errors).and_return('anything')

( Location - , response_with)

, - , !

. , , !

+5

All Articles