vendredi 14 avril 2017

Rspec request specs and Rails 5

I'm starting a new project, my first with Rails 5.1.0. I have a pb with my first request spec.

describe 'Users', type: :request do
  it 'are created from external data' do
    json_string = File.read('path/to/test_data/user_data.json')
    params = { user: JSON.parse(json_string) }
    headers = { "CONTENT_TYPE" => "application/json" }

    expect do
      post '/api/v1/users', params.to_s, headers
    end.to change {
      User.count
    }.by(1)

    expect(response.status).to eq 200
  end
end

this spec return the error ArgumentError: wrong number of arguments (given 3, expected 1). The official documentation don't say much.

If I take out the headers, like this:

post '/api/v1/users', params

I got another error:

ArgumentError: unknown keyword: user

Any thought?

Aucun commentaire:

Enregistrer un commentaire