Reputation: 38772
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?
Upvotes: 10
Views: 4902
Reputation: 326
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"}))
Upvotes: 18
Reputation: 12826
Use Rack::MockRequest
which is implemented for this purpose. See these tests for example usage.
Upvotes: 7