Ruby, how to create a Rack::Request for testing purposes?

rack, request, ruby, unit-testing

Solution

Rack itself includes some unit tests for `Rack::Request`, you can use them as a starting point (example).

Rack::Request.new(Rack::MockRequest.env_for("http://example.com:8080/", {"REMOTE_ADDR" => "10.10.10.10"}))

Problem

I have a library that take a `Rack::Request` and do stuff on it. I would like to test it from an unit test and not from a functional test. So I have to create a `Rack::Request` instance on my own, how can I do it?

Original source