Skip to content

Commit

Permalink
Rack::Logger conforms to Rack::Lint, closes Lighthouse rack#89
Browse files Browse the repository at this point in the history
  • Loading branch information
raggi committed May 23, 2011
1 parent 5aa4a33 commit 51cdaa6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 0 additions & 2 deletions lib/rack/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ def call(env)

env['rack.logger'] = logger
@app.call(env)
ensure
logger.close
end
end
end
24 changes: 16 additions & 8 deletions test/spec_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@
require 'rack/logger'

describe Rack::Logger do
should "log to rack.errors" do
app = lambda { |env|
log = env['rack.logger']
log.debug("Created logger")
log.info("Program started")
log.warn("Nothing to do!")
app = lambda { |env|
log = env['rack.logger']
log.debug("Created logger")
log.info("Program started")
log.warn("Nothing to do!")

[200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
}
[200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
}

should "log to rack.errors" do
errors = StringIO.new
Rack::Logger.new(app).call('rack.errors' => errors)
errors.string.should.match(/INFO -- : Program started/)
errors.string.should.match(/WARN -- : Nothing to do/)
end

should "conform to Rack::Lint" do
errors = StringIO.new
a = Rack::Lint.new(Rack::Logger.new(app))
Rack::MockRequest.new(a).get('/', 'rack.errors' => errors)
errors.string.should.match(/INFO -- : Program started/)
errors.string.should.match(/WARN -- : Nothing to do/)
end
end

0 comments on commit 51cdaa6

Please sign in to comment.