Skip to content

Add test helpers for building custom rack requests #169

@jcredding

Description

@jcredding

It would be nice if we could provide helpers for building custom rack requests. Being able to easily set request headers, the path info, the request method, the query string and the body would be nice. For example, with a request whose body is JSON, you have to do something like:

request = Rack::Request.new({
  'CONTENT_TYPE' => 'application/json',
  'rack.input'   => StringIO.new("{ number: 1 }")
})

We could pass "fake" requests using custom structs but this can get annoying the more things you depend on the request for. Also having to know rack's "structure" for headers and the body is not awesome. I think something ideal would be:

test_runner(@handler_class, {
  :request => {
    :headers => { 'Content-Type' => 'application/json' },
    :body    => "{ number: 1 }"
  }
})
# OR, to avoid nesting hashes
test_runner(@handler_class, {
  :request_headers => { 'Content-Type' => 'application/json' },
  :request_body    => "{ number: 1 }"
})

Ideally, deas would handle building a StringIO for us and setting up the rack env correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions