Skip to content

Instantly share code, notes, and snippets.

@bhb
Created April 23, 2010 17:13
Show Gist options
  • Save bhb/376828 to your computer and use it in GitHub Desktop.
Save bhb/376828 to your computer and use it in GitHub Desktop.
module Rack
class Cap
def initialize(app, options = {})
@app = app
end
def call(env)
response = @app.call(env)
status, headers, body = response
headers['Content-Length']= body.length.to_s
[status, headers, body.map {|x| x.upcase+"!"}]
end
end
end
require 'test/unit'
require 'shoulda'
require 'rack'
class CapTest < Test::Unit::TestCase
should 'capitalize body' do
inner_app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['Hello']] }
app = Rack::Cap.new(inner_app)
env = Rack::MockRequest.env_for('/hello')
status, headers, body = app.call(env)
assert_equal ['HELLO!'], body
end
should 'pass all Lint checks' do
inner_app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['Hello']] }
app = Rack::Lint.new(Rack::Cap.new(inner_app))
env = Rack::MockRequest.env_for('/hello')
app.call(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment