Rack middleware that stubs paths and returns data you tell it to
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Endpoint Stub Manager

This is just a tiny piece of Rack middleware to use as a stub helper in a testing environment. Basically, you post to a url (defined by STUB_PATH) which accepts a params hash with a path that maps to a response body. The Stub Manager will store the path and it's associated data internally in @stubs. From then on, when you hit a path stored in @stubs, it'll return the data associated with that path. On a high level, this allows you to specify paths of your app that you want to stub out and have it return the data you tell it to.


Insert the Rack middleware in your config/environments/test.rb. From there, in your tests, as part of a test setup, send a post request to whatever you defined STUB_PATH to be. The post request params should look something like:

{ stubs: { "some/path": { status: "200", headers: {"Content-Type": "text/html"}, body: "Stubbed response" } } }