forked from rack/rack
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import Config by jcrosby (Jon Crosby) into core
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Rack | ||
# Rack::Config modifies the environment using the block given during | ||
# initialization. | ||
class Config | ||
def initialize(app, &block) | ||
@app = app | ||
@block = block | ||
end | ||
|
||
def call(env) | ||
@block.call(env) | ||
@app.call(env) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'test/spec' | ||
require 'rack/mock' | ||
require 'rack/builder' | ||
require 'rack/content_length' | ||
require 'rack/config' | ||
|
||
context "Rack::Config" do | ||
|
||
specify "should accept a block that modifies the environment" do | ||
app = Rack::Builder.new do | ||
use Rack::Lint | ||
use Rack::ContentLength | ||
use Rack::Config do |env| | ||
env['greeting'] = 'hello' | ||
end | ||
run lambda { |env| | ||
[200, {'Content-Type' => 'text/plain'}, [env['greeting'] || '']] | ||
} | ||
end | ||
response = Rack::MockRequest.new(app).get('/') | ||
response.body.should.equal('hello') | ||
end | ||
|
||
end |