title: Testing an AJAX POST using Rack::Test - how to pass in data?
body: <p>I'm using <a href="https://github.com/brynary/rack-test" rel="nofollow">Rack::Test</a> to test my app and need to test the posting of data via AJAX.</p>
  
  <p>My test looks like:</p>
  
  <pre><code>describe 'POST /user/' do
    include Rack::Test::Methods
    it 'must allow user registration with valid information' do
      post '/user', {
        username: 'test_reg',
        password: 'test_pass',
        email: 'test@testreg.co'
      }.to_json, {"CONTENT_TYPE" =&gt; 'application/json', "HTTP_X_REQUESTED_WITH" =&gt; "XMLHttpRequest"}
      last_response.must_be :ok?
      last_response.body.must_match 'test_reg has been saved'
    end
  end
  </code></pre>
  
  <p>But at the server end it's not receiving the POSTed data.</p>
  
  <p>I also tried just passing in the params hash without the <code>to_json</code> but that made no difference.</p>
  
  <p>Any idea how to do this?</p>