title: Michael Hartl's Rails Tutorial: Rspec's "Expected response to be a redirect to ..." is wrong
body: <p>In Michael Hartl's (wonderful) Rails Tutorial I'm getting an unexpected Rspec test failure of the form:  </p>
  
  <blockquote>
    <p>"Expected response to be a redirect to
    &lt;<a href="http://test.host/signin" rel="nofollow">http://test.host/signin</a>> but was a
    redirect to
    &lt;<a href="http://test.host/signin?notice=Please+sign+in+to+access+this+page." rel="nofollow">http://test.host/signin?notice=Please+sign+in+to+access+this+page.</a>>."</p>
  </blockquote>
  
  <p>(Find this in Section 10.3.) So, from the very error, you can se that the server is redirecting to the appropriate page except that there is an additional notice to "Please sign in".  The code of the test looks like this:</p>
  
  <pre><code>describe "GET 'index'" do
  
  describe "for non-signed-in users" do
    it "should deny access" do
      get :index
      response.should redirect_to(signin_path)
      flash[:notice].should =~ /sign in/i
    end
  end
  
  ...
  </code></pre>
  
  <p>Am I doing something wrong here?  How best should I fix this?</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>If I change the code to  </p>
  
  <pre><code>response.should redirect_to('http://test.host/signin?notice=Please+sign+in+to+access+this+page.')
  </code></pre>
  
  <p>then I get and actual Ruby error</p>
  
  <blockquote>
    <p>Failure/Error: flash[:notice].should
    =~ /sign in/i
         expected: /sign in/i,
              got: nil (using =~)</p>
  </blockquote>
  
  <hr>
  
  <p><strong>Resolution</strong></p>
  
  <p>The problem was an omitted comma in my deny_access function:</p>
  
  <pre><code>redirect_to signin_path :notice =&gt; "Please sign in to access this page."
  </code></pre>
  
  <p>should have been</p>
  
  <pre><code>redirect_to signin_path, :notice =&gt; "Please sign in to access this page."
  </code></pre>
  
  <p>This fixed it.  Now, the side affect of this fix was interesting wasn't it?  Does this imply that <code>signin_path</code> is itself a function that can take a hash or arguments to be appended to the end of the path?  Weird, wild, and wonderful.</p>