title: Rspec request spec's empty response
body: <p>I'm trying to write a request spec for my first Rails app, but the response object is <code>nil</code>.  Rspec is still dark magic to me, so I may be missing something really basic, but given the example <a href="https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec#requesting-a-json-response" rel="nofollow noreferrer">here</a> I figured this would work.  When I run the Rails server, I can authenticate over cURL, and my controller spec works fine.</p>
  
  <p>Here's my request spec:</p>
  
  <pre class="lang-rb prettyprint-override"><code># spec/requests/tokens_request_spec.rb
  require 'rails_helper'
  
  RSpec.describe Api::V1::TokensController, type: :request do
    context "getting the token" do
      let(:user) { create(:user) }
  
      it 'status code is 2xx' do
        post "/api/v1/login", { auth: { email: user.email, password: user.password } }, { accept: "application/json" }
        expect(response).to have_http_status(:success)
      end
    end
  end
  </code></pre>
  
  <p>Here's my controller:</p>
  
  <pre class="lang-rb prettyprint-override"><code># app/controllers/api/v1/tokens_controller.rb
  class Api::V1::TokensController &lt; ApplicationController
    def create
      user = User.find_by(email: user_params["email"])
      return render json: { jwt: Auth.issue(user: user.id) } if user.authenticate(user_params["password"])
      render json: { message: "Invalid credentials" }, status: 401
    end
  
    private
  
    def user_params
      params.require(:auth).permit(:email, :password)
    end
  end
  </code></pre>
  
  <p>Here's my test output: </p>
  
  <pre class="lang- prettyprint-override"><code>Failures:
  
    1) Api::V1::TokensController getting the token status code is 2xx
       Failure/Error: expect(response).to have_http_status(:success)
         expected the response to have a success status code (2xx) but it was
       # ./spec/requests/tokens_request_spec.rb:13:in `block (3 levels) in &lt;top (required)&gt;'
       # ./spec/spec_helper.rb:27:in `block (3 levels) in &lt;top (required)&gt;'
       # ./spec/spec_helper.rb:26:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>Any help is greatly appreciated.</p>