title: Rails JSON API testing POST request with PARAMS in JSON
body: <p>This is a problem that has been bothering me for some time. I am building an API function that should receive data in json and response in json. My controller tests run fine(Since I abstract that the data gets there already decode from JSON and only the answer needs to be interpreted ). </p>
  
  <p>I Also know that the function runs fine since I have used curl to test it with JSON arguments and it works perfectly. 
  (ex: curl -i --header "Accept: application/json" --header "Content-Type: application/json" -d '{"test":{"email":"andreo@benjamin.dk"}}' )</p>
  
  <p>But obviously I would like to write request(feature) tests to test this automatically and the way I see it they should work exactly like curl, i.e., hit my service like it was an external call. That means that I would like to pass the arguments in JSON and receive an answer. I am pretty lost since all the examples I can see people treat arguments as it was already decoded. </p>
  
  <p>My question is: I am following a wrong premise in wanting to send the arguments and request as a JSON one since i will be testing that rails works, because this is its responsibility? But I would like to see how robust my code his to wrong arguments and would like to try with JSON.</p>
  
  <p>something of this type:</p>
  
  <pre><code>it "should return an error if there is no correct email" do
      params = {:subscription =&gt; {:email =&gt; "andre"}}
  
      post "/magazine_subscriptions", { 'HTTP_ACCEPT' =&gt; "application/json", 'Content-Type' =&gt; 'application/json', 'RAW_POST_DATA' =&gt; params.to_json }
  end
  </code></pre>
  
  <p>Do you know how this is possible? and please let me know if you think I am testing it wrong.</p>
  
  <p>all the best,</p>
  
  <p>Andre</p>