intridea/grape — pull request #397 by mbleigh (2013-04-29 22:34:11+00:00)
Title: Adds Grape::Endpoint.setup for pre-run endpoint config.

This pull request addresses #396 by providing a `Grape::Endpoint.setup` class method which can be used to manipulate an Endpoint just before it begins executing. The use of this in a test suite would go something like this:

Let's say I have a `current_user` helper that I want to stub. Let's say I don't even have it implemented yet, but I don't want it to error out while I'm building my library. Simple!

```ruby
describe MyAPI do
let(:app){ MyAPI }

context 'with a logged in user' do
before do
Grape::Endpoint.setup do |endpoint|
endpoint.stub(:current_user).and_return mock(:User, name: "Bob Example")
end
end

after{ Grape::Endpoint.setup nil }
end
end
```

I'm entering this as a pull request for a few reasons:

1. It adds code that will be conditionally executed every time any endpoint is called. I don't take that super lightly.
2. Right now there is only the ability to do a single `setup` step which precludes nesting or multiple layers of setup. I'm not sure if this is the right way to go, but I wanted to start with a straightforward implementation.

Thoughts?