title: nil response object in Rails 5.2, RSpec-Rails 3.7 spec for GET request
body: <p>I've been heads down in this and feel like I'm probably making a simple mistake, but I haven't been able to find any information on this problem.</p>
  
  <p>I have some request specs for Rails 5 and, when I test for a redirect--but not for a rendered template--I get an error, <code>undefined method 'response_code' for nil:NilClass</code>. The reason for this seems to be that <code>@response</code> is <code>nil</code> when the matcher is called (inside ActionDispatch::Assertions::ResponseAssertions code, not in my code). I am able to use cURL to make a request to the API and it returns a response as expected. The point where the error is returned is here (this is the ActionDispatch code):</p>
  
  <pre><code>def generate_response_message(expected, actual = @response.response_code)
    "Expected response to be a &lt;#{code_with_name(expected)}&gt;,"\
    " but was a &lt;#{code_with_name(actual)}&gt;"
    .dup.concat(location_if_redirected).concat(response_body_if_short)
  end
  </code></pre>
  
  <p>Notice the first line, where the default value of the <code>actual</code> param is set to <code>@response.response_code</code>.</p>
  
  <p>Here's my test code:</p>
  
  <pre><code>RSpec.describe "Admin registrations", type: :request do
    describe "new sign-up" do
      subject { get new_admin_registration_path }
  
      it "redirects to home" do
         expect(subject).to redirect_to(new_admin_session_path)
      end
    end
  end
  </code></pre>
  
  <p>The relevant lines in the test log are:</p>
  
  <pre><code>Started GET "/admins/sign_up" for 127.0.0.1 at 2018-07-05 10:44:05 -0700
  Processing by Admins::RegistrationsController#new as HTML
  Redirected to http://example.org/admins/sign_in
  Completed 301 Moved Permanently in 18ms (ActiveRecord: 0.0ms)
  </code></pre>
  
  <p>Interestingly, when I use byebug to check the value of <code>subject</code>, it does return a Rack::MockResponse object, so this is somehow not getting passed through.</p>
  
  <p>Any help I can get with this is much appreciated!</p>