RSwag `consumes` method does work in RSpec context

25 Views Asked by At

I am trying to test for wrong content type with RSwag and I put consumes method in a shared context

path '/api/profile' do
  get 'profile' do
    consumes 'application/json'
    produces 'application/json'
    
    it_behaves_like 'handles errors'

    response(200, 'it works') do
      run_test!
    end
  end
end

shared_examples 'handles errors' do
  context 'no credentials' do
    response(401, 'unauthorized') do
      run_test!
    end
  end

  context 'wrong data type' do
    consumes 'text/html'
    response(415, 'unsupported media type') do
      run_test!
    end
  end
end

This is not working because consumes seems to override Content-Type for other test cases as well. I can pass 'Content-Type' header manually, but it seems redundant. Is this by design? Is there any convenient workaround?

0

There are 0 best solutions below