Sha256: a2e82e0f33cb5acd7256f764bfc4a74b48e9b73ff05b5f4adfe44e5d5780f7c6

Contents?: true

Size: 1.35 KB

Versions: 18

Compression:

Stored size: 1.35 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
    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

18 entries across 16 versions & 4 rubygems

Version Path
candlepin-api-0.4.0 bundle/ruby/1.8/gems/rack-1.3.5/test/spec_commonlogger.rb
candlepin-api-0.4.0 bundle/ruby/gems/rack-1.3.5/test/spec_commonlogger.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/rack-1.3.5/test/spec_commonlogger.rb
rack-1.3.10 test/spec_commonlogger.rb
rack-1.3.9 test/spec_commonlogger.rb
rack-1.3.8 test/spec_commonlogger.rb
rack-1.3.7 test/spec_commonlogger.rb
rack-1.3.6 test/spec_commonlogger.rb
rack-1.3.5 test/spec_commonlogger.rb
rack-1.3.4 test/spec_commonlogger.rb
rack-1.3.3 test/spec_commonlogger.rb
rack-1.3.2 test/spec_commonlogger.rb
rack-1.3.1 test/spec_commonlogger.rb
search_biomodel-1.0.0 search_biomodel/ruby/1.8/gems/rack-1.3.0/test/spec_commonlogger.rb
rack-1.3.0 test/spec_commonlogger.rb
rack-1.3.0.beta2 test/spec_commonlogger.rb
rack-1.3.0.beta test/spec_commonlogger.rb
edgar-rack-1.2.1 test/spec_commonlogger.rb