Sha256: a1bcc37cc9ca82585d9a366b83c49e3224c4f0e6c120200de7ce45afd32fe531

Contents?: true

Size: 1.36 KB

Versions: 9

Compression:

Stored size: 1.36 KB

Contents

require 'rack/commonlogger'
require 'rack/mock'

describe Rack::CommonLogger do
  obj = 'foobar'
  length = obj.size

  app = lambda { |env|
    [200,
     {"Content-Type" => "text/html", "Content-Length" => length.to_s},
     [obj]]}
  app_without_length = lambda { |env|
    [200,
     {"Content-Type" => "text/html"},
     []]}
  app_with_zero_length = lambda { |env|
    [200,
     {"Content-Type" => "text/html", "Content-Length" => "0"},
     []]}

  should "log to rack.errors by default" do
    res = Rack::MockRequest.new(Rack::CommonLogger.new(app)).get("/")

    res.errors.should.not.be.empty
    res.errors.should =~ /"GET \/ " 200 #{length} /
  end

  should "log to anything with +write+" do
    log = StringIO.new
    res = Rack::MockRequest.new(Rack::CommonLogger.new(app, log)).get("/")

    log.string.should =~ /"GET \/ " 200 #{length} /
  end

  should "log - content length if header is missing" do
    res = Rack::MockRequest.new(Rack::CommonLogger.new(app_without_length)).get("/")

    res.errors.should.not.be.empty
    res.errors.should =~ /"GET \/ " 200 - /
  end

  should "log - content length if header is zero" do
    res = Rack::MockRequest.new(Rack::CommonLogger.new(app_with_zero_length)).get("/")

    res.errors.should.not.be.empty
    res.errors.should =~ /"GET \/ " 200 - /
  end

  def length
    123
  end

  def self.obj
    "hello world"
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rack-1.2.8 test/spec_commonlogger.rb
rack-1.2.7 test/spec_commonlogger.rb
rack-1.2.6 test/spec_commonlogger.rb
rack-1.2.5 test/spec_commonlogger.rb
rack-1.2.4 test/spec_commonlogger.rb
rack-1.2.3 test/spec_commonlogger.rb
rack-1.2.2 test/spec_commonlogger.rb
rack-1.2.1 test/spec_commonlogger.rb
rack-1.2.0 spec/spec_commonlogger.rb