RSpec request test merges hashes in array in POST JSON params

json, parameters, request, rspec, ruby-on-rails

Solution

Got it! array of hashes is not supported for form-data RSpec by default posts it as form-data. Solution:

post '...', {...}.to_json, {'CONTENT_TYPE' => "application/json", 'ACCEPT' => 'application/json'}

Problem

Looks like a bug in RSpec but maybe I'm missing something. I have a request spec where I post a JSON that contains an array of hashes: spec/requests/dummy_request_spec.rb: ``` post "http://my.server.com/some/route", { format: :json, data: [ { details: { param1: 1 }, }, { details: { param2: 1 } } ] } ``` For some odd reason, RSpec merges the hashes into one element and then sends them to server. print out of params received in controller: ``` data: [ { details: { param1: 1, param2: 2 }, }, ] ``` versions: rspec-2.13.0 rails-3.2.10 Very strange!! Thanks

Original source

Related problems