Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1.3 and Inherited Resources tests fail

I'm using Rails 3.1.3 for a project with Inherited Resources 1.3.0.

When I have a controller like so:

class PostsController < InheritedResources::Base
end

And I test with rspec the following

  describe "PUT update" do
    describe "with invalid params" do
      it "re-renders the 'edit' template" do
        post = Post.create! valid_attributes
        # Trigger the behavior that occurs when invalid params are submitted
        Post.any_instance.stub(:save).and_return(false)
        put :update, {:id => post.to_param, :post => {}}, valid_session
        response.should render_template("edit")
      end
    end
  end

I get the following error:

  3) PostsController PUT update with invalid params re-renders the 'edit' template
     Failure/Error: response.should render_template("edit")
       expecting <"edit"> but rendering with <"">
     # ./spec/controllers/posts_controller_spec.rb:115:in `block (4 levels) in <top (required)>'

Why is this? Do I have to stub something else out?

like image 259
map7 Avatar asked Feb 08 '12 03:02

map7


1 Answers

Just add this:

Post.any_instance.stub(:errors).and_return(['error'])

right after:

Post.any_instance.stub(:save).and_return(false)
like image 85
Cody Swann Avatar answered Oct 30 '22 12:10

Cody Swann