How do you specify Content-Type (and other headers) and request body in RSpec Rails Controller test? How do you specify Content-Type (and other headers) and request body in RSpec Rails Controller test? json json

How do you specify Content-Type (and other headers) and request body in RSpec Rails Controller test?


In RSpec 1.3 you can operate on a "request" variable. Something like this should work for you:

request.env['CONTENT_TYPE'] = 'application/json'post :method_name


I use post :method_name, { :format => :json, ... other parameter data }