Sha256: 727510ab2fc2cd0f2cc0725c7d31c247e9856db2616be2fdbd77bc75c847852a

Contents?: true

Size: 1.42 KB

Versions: 190

Compression:

Stored size: 1.42 KB

Contents

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

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

  app = Rack::Lint.new lambda { |env|
    [200,
     {"Content-Type" => "text/html", "Content-Length" => length.to_s},
     [obj]]}
  app_without_length = Rack::Lint.new lambda { |env|
    [200,
     {"Content-Type" => "text/html"},
     []]}
  app_with_zero_length = Rack::Lint.new 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

190 entries across 160 versions & 31 rubygems

Version Path
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_commonlogger.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_commonlogger.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_commonlogger.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_commonlogger.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_commonlogger.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_commonlogger.rb
classiccms-0.3.8 vendor/bundle/gems/rack-1.4.1/test/spec_commonlogger.rb
challah-0.6.1 vendor/bundle/gems/rack-1.4.1/test/spec_commonlogger.rb
classiccms-0.3.7 vendor/bundle/gems/rack-1.4.1/test/spec_commonlogger.rb
classiccms-0.3.6 vendor/bundle/gems/rack-1.4.1/test/spec_commonlogger.rb
classiccms-0.3.5 vendor/bundle/gems/rack-1.4.1/test/spec_commonlogger.rb
classiccms-0.3.4 vendor/bundle/gems/rack-1.4.1/test/spec_commonlogger.rb
classiccms-0.3.3 vendor/bundle/gems/rack-1.4.1/test/spec_commonlogger.rb
classiccms-0.3.2 vendor/bundle/gems/rack-1.4.1/test/spec_commonlogger.rb
classiccms-0.3.1 vendor/bundle/gems/rack-1.4.1/test/spec_commonlogger.rb
classiccms-0.3.0 vendor/bundle/gems/rack-1.4.1/test/spec_commonlogger.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_commonlogger.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_commonlogger.rb
rails-uploader-0.0.1 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_commonlogger.rb
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/rack-1.4.1/test/spec_commonlogger.rb