title: rspec controller testing, Expected response to be a <redirect>, but was <200>
body: <p>I'm using rspec and Factory Girl for testing. When testing the POST #create section of my posts_controller I'm getting the error in the title.</p>
  
  <pre><code>Failures:
  
    1) PostsController POST #create with valid attributes redirects to the post
       Failure/Error: response.should redirect_to Post.last
         Expected response to be a &lt;redirect&gt;, but was &lt;200&gt;
       # ./spec/controllers/posts_controller_spec.rb:59:in `block (4 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>This is the code from the spec being tested. I'm sure it's not the most efficient way of doing this, but it does work.</p>
  
  <pre><code>  def create
  
      @post = Post.new(
        :text =&gt; post_params[:text],
        :embed =&gt; post_params[:embed],
        :user =&gt; current_user,
        :title =&gt; post_params[:title],
        :tag_list =&gt; post_params[:tag_list],
        :cagegory_ids =&gt; post_params[:category_ids]
      )
  
  
      if @post.save
        redirect_to @post
      else
        render 'new'
      end
  
    end
  
  ...
  
    private    
      def post_params
        params.require(:post).permit(:title, :text, :embed, :user_id, :tag_list,
                                 :category_ids =&gt; [])
      end
  </code></pre>
  
  <p>Here's the factory.    </p>
  
  <pre><code>FactoryGirl.define do  
    factory :post do
      title { Faker::Lorem.characters(char_count = 20) }
      text { Faker::Lorem.characters(char_count = 150) }
      user
      categories {
        Array(5..10).sample.times.map do
          FactoryGirl.create(:category)
        end
      }
    end
  end
  </code></pre>
  
  <p>And the relevant part of the spec</p>
  
  <pre><code>  describe "POST #create" do
      context "with valid attributes" do
        it "saves the new post" do
          expect{
                  post :create, post: FactoryGirl.create(:post).attributes
                }.to change(Post,:count).by(1)
  
        end
  
        it "redirects to the post" do
          post :create, post: FactoryGirl.create(:post).attributes
          response.should redirect_to Post.last
        end        
      end
    end
  </code></pre>
  
  <p>The other test, "saves the new post," works fine. I've tried other variations of the redirect_to line, such as "redirect_to(posts_path(assigns[:post])) and it throws the same error.</p>
  
  <p>Any ideas?</p>