Skip to content

Error when executing POST json request #20

Description

@nicopaez

I am trying to generate the spec for a POST request that sends json message in the body and I getting the error below.

 ActionDispatch::Http::Parameters::ParseError:
            no implicit conversion of nil into String
          # /usr/local/bundle/gems/actionpack-6.0.3.3/lib/action_dispatch/http/parameters.rb:114:in `rescue in parse_formatted_parameters'
          # /usr/local/bundle/gems/actionpack-6.0.3.3/lib/action_dispatch/http/parameters.rb:110:in `parse_formatted_parameters'
          # /usr/local/bundle/gems/actionpack-6.0.3.3/lib/action_dispatch/http/request.rb:389:in `block in POST'
          # /usr/local/bundle/gems/rack-2.2.3/lib/rack/request.rb:69:in `fetch'
          # /usr/local/bundle/gems/rack-2.2.3/lib/rack/request.rb:69:in `fetch_header'
          # /usr/local/bundle/gems/actionpack-6.0.3.3/lib/action_dispatch/http/request.rb:388:in `POST'
          # /usr/local/bundle/gems/rspec-openapi-0.3.13/lib/rspec/openapi/record_builder.rb:94:in `raw_request_params'
          # /usr/local/bundle/gems/rspec-openapi-0.3.13/lib/rspec/openapi/record_builder.rb:41:in `build'
          # /usr/local/bundle/gems/rspec-openapi-0.3.13/lib/rspec/openapi/hooks.rb:12:in `block in <top (required)>'
          # ------------------
          # --- Caused by: ---
          # TypeError:
          #   no implicit conversion of nil into String
          #   /usr/local/bundle/gems/activesupport-6.0.3.3/lib/active_support/json/decoding.rb:23:in `decode'

this is my rspec:


      it 'create a user' do
        header 'CONTENT_TYPE', 'application/json'
        json_data = { name: 'juan'}.to_json
        post '/users', json_data, { 'Content-Type' => 'application/json' }
        expect(last_response.status).to eq(201)
      end

I notice that if I remove the fist line (header 'CONTENT_TYPE', 'application/json') then the execution completes successfully but the result yaml spec is wrong, it specifies request.content type as application/x-www-form-urlencoded instead of application/json.

I am running ruby 2.5.7p206 and my application is padrino application (not rails).

If anyone can give some guidance I my try to submit a fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions