heroku/committee — pull request #18 by brandur (2014-04-26 17:32:47+00:00)
Title: Optionally allow application to intercept and modify stubbed responses

A stub has traditionally been quite rigid in Committee -- when activated for a response, it returns only what it finds in the example fields of a JSON schema. This may be too inflexible for all purposes, especially for test suites that need to be able to interact with their stub with more fine-grain control.

This pull adds the `call` option to the `Committee::Middleware::Stub`. When activated, it continues to intercept requests that fit into a JSON Schema, but when it does, it will fill `env["committee.response"]` with the data it intends to respond with, and call down into the application stack. The data in `committee.response` can then be either modified or replaced completely the downstream application.

This will enable the construction of "hybrid stubs", which leverage the raw JSON Schema responses where possible, but override on some endpoints for more flexibility.

``` ruby
Rack::Builder.new {
use Committee::Middleware::Stub, call: true, schema: File.read("schema.json")
run Sinatra.new {
get "/apps" do
# just tweak a single parameter
env["committee.response"]["name"] = "heroku-api",
end
}
}
```

```
$ curl http://localhost:5000/apps
{
..
"name": "heroku-api",
..
}
```