Sha256: 0e5dcf7c84856f02514932cc37bb04eaf5b8cf5e7e414b39bc6a17d23a4065c7

Contents?: true

Size: 1.47 KB

Versions: 22

Compression:

Stored size: 1.47 KB

Contents

require 'test/spec'
require 'stringio'

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

context "Rack::CommonLogger" do
  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"},
     []]}

  specify "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

  specify "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

  specify "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

  specify "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
    self.class.length
  end
  
  def self.length
    123
  end
  
  def self.obj
    "hello world"
  end
end

Version data entries

22 entries across 21 versions & 10 rubygems

Version Path
kjvarga-rack-1.0.0 test/spec_rack_commonlogger.rb
qoobaa-rack-1.0.0.1 test/spec_rack_commonlogger.rb
qoobaa-rack-1.0.2 test/spec_rack_commonlogger.rb
rack-1.1.6 test/spec_rack_commonlogger.rb
rack-1.1.5 test/spec_rack_commonlogger.rb
rack-1.1.4 test/spec_rack_commonlogger.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rack-1.1.3/test/spec_rack_commonlogger.rb
rack-1.1.3 test/spec_rack_commonlogger.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/rack-1.1.2/test/spec_rack_commonlogger.rb
rack-1.1.2 test/spec_rack_commonlogger.rb
rack-1.1.1 test/spec_rack_commonlogger.rb
rack-1.1.1.pre test/spec_rack_commonlogger.rb
eac-rack-1.1.1 test/spec_rack_commonlogger.rb
akamai_bookmarklet-0.1.2 vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_commonlogger.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/rack-1.1.0/test/spec_rack_commonlogger.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_commonlogger.rb
akamai_bookmarklet-0.1.1 vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_commonlogger.rb
akamai_bookmarklet-0.1.0 vendor/gems/ruby/1.8/gems/rack-1.1.0/test/spec_rack_commonlogger.rb
rack-1.1.0 test/spec_rack_commonlogger.rb
rango-0.0.6 vendor/rack/test/spec_rack_commonlogger.rb