I am trying to write a failing spec for passing a invalid json when making a request to a rails api endpoint.
In a full rail api I would have used capybara and curl to make the actual request.
How do I pass a invalid json via a rspec request spec?
I am trying to write a failing spec for passing a invalid json when making a request to a rails api endpoint.
In a full rail api I would have used capybara and curl to make the actual request.
How do I pass a invalid json via a rspec request spec?
I ended up finding a solution to this, you need to use request specs, something along this lines:
require 'rails_helper'
RSpec.describe 'JSON formatting', :type => :request do
context 'with bad json' do
it 'returns 400 on bad json' do
headers = {
'ACCEPT' => 'application/json',
'CONTENT_TYPE' => 'application/json'
}
post '/some/path', "{", headers
expect(response.content_type).to eq("application/json")
end
end
end