title: RSpec's post and get methods fail to recognize non-existing routes
body: <p>I'm doing <em>request</em> specs for a JSON REST API using a BDD approach. This means specs will fail by default, since nothing is really implemented, including routes. Here's a simple example:</p>
  
  <pre><code>  describe 'POST /users' do
      context 'when the request is valid' do
        before { post "/users", params: {userName: 'johndoe22'}}
  
        it 'creates and returns the user' do
          expect(json['userName']).to eq('johndoe22')
        end
  
        it 'returns status code 201 (created)' do
          expect(response).to have_http_status(201)
        end
      end
      ...
    end
  </code></pre>
  
  <p>Basically I request something (either using <em>get</em> or <em>post</em>), then I parse the response as JSON. The problem is, if <em>/users</em> does not exist, instead of getting an <em>ActionController::RoutingError: No route matches</em> error, <em>post</em> fails silently and then the spec fails when I try to parse the response as JSON. This response actually contains the <em>no route matches</em> error.</p>
  
  <p>In other words, instead of failing right when the <em>post</em> method is called, the test fails later when I try to parse the response (a regular HTML page which cannot be parsed to JSON).</p>
  
  <pre><code>Failure/Error: JSON.parse(response.body)
  
   JSON::ParserError:
     784: unexpected token at '&lt;!DOCTYPE html&gt;
     &lt;html lang="en"&gt;
     ...
  </code></pre>
  
  <p>For reference, I'm loosely following this tutorial: <a href="https://scotch.io/tutorials/build-a-restful-json-api-with-rails-5-part-one" rel="nofollow noreferrer">https://scotch.io/tutorials/build-a-restful-json-api-with-rails-5-part-one</a>. As you can see, he gets the appropriate error when doing request specs.</p>
  
  <p>Why is this happening? Am I missing some sort of configuration? </p>