spec_logger.rb 822 B

12345678910111213141516171819202122232425262728
  1. require 'stringio'
  2. require 'rack/logger'
  3. describe Rack::Logger do
  4. app = lambda { |env|
  5. log = env['rack.logger']
  6. log.debug("Created logger")
  7. log.info("Program started")
  8. log.warn("Nothing to do!")
  9. [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
  10. }
  11. should "log to rack.errors" do
  12. errors = StringIO.new
  13. Rack::Logger.new(app).call('rack.errors' => errors)
  14. errors.string.should.match(/INFO -- : Program started/)
  15. errors.string.should.match(/WARN -- : Nothing to do/)
  16. end
  17. should "conform to Rack::Lint" do
  18. errors = StringIO.new
  19. a = Rack::Lint.new(Rack::Logger.new(app))
  20. Rack::MockRequest.new(a).get('/', 'rack.errors' => errors)
  21. errors.string.should.match(/INFO -- : Program started/)
  22. errors.string.should.match(/WARN -- : Nothing to do/)
  23. end
  24. end