Sha256: e39fee520d13b5af7662e6d1745ec413f033ba97f627554f55e30e3eaa76e100

Contents?: true

Size: 1.69 KB

Versions: 43

Compression:

Stored size: 1.69 KB

Contents

require 'rack/mock'
require 'rack/content_length'

context "Rack::ContentLength" do
  specify "sets Content-Length on String bodies if none is set" do
    app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
    response = Rack::ContentLength.new(app).call({})
    response[1]['Content-Length'].should.equal '13'
  end

  specify "sets Content-Length on Array bodies if none is set" do
    app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
    response = Rack::ContentLength.new(app).call({})
    response[1]['Content-Length'].should.equal '13'
  end

  specify "does not set Content-Length on variable length bodies" do
    body = lambda { "Hello World!" }
    def body.each ; yield call ; end

    app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
    response = Rack::ContentLength.new(app).call({})
    response[1]['Content-Length'].should.be.nil
  end

  specify "does not change Content-Length if it is already set" do
    app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '1'}, "Hello, World!"] }
    response = Rack::ContentLength.new(app).call({})
    response[1]['Content-Length'].should.equal '1'
  end

  specify "does not set Content-Length on 304 responses" do
    app = lambda { |env| [304, {'Content-Type' => 'text/plain'}, []] }
    response = Rack::ContentLength.new(app).call({})
    response[1]['Content-Length'].should.equal nil
  end

  specify "does not set Content-Length when Transfer-Encoding is chunked" do
    app = lambda { |env| [200, {'Transfer-Encoding' => 'chunked'}, []] }
    response = Rack::ContentLength.new(app).call({})
    response[1]['Content-Length'].should.equal nil
  end
end

Version data entries

43 entries across 42 versions & 15 rubygems

Version Path
kjvarga-rack-1.0.0 test/spec_rack_content_length.rb
p8-castronaut-0.6.1.1 vendor/rack/test/spec_rack_content_length.rb
qoobaa-rack-1.0.0.1 test/spec_rack_content_length.rb
qoobaa-rack-1.0.2 test/spec_rack_content_length.rb
relevance-castronaut-0.6.0 vendor/rack/test/spec_rack_content_length.rb
relevance-castronaut-0.6.1 vendor/rack/test/spec_rack_content_length.rb
relevance-castronaut-0.7.4 vendor/rack/test/spec_rack_content_length.rb
relevance-castronaut-0.7.5 vendor/rack/test/spec_rack_content_length.rb
timocratic-rack-1.0.0 test/spec_rack_content_length.rb
rack-1.1.6 test/spec_rack_content_length.rb
rack-1.1.5 test/spec_rack_content_length.rb
rack-1.1.4 test/spec_rack_content_length.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rack-1.1.3/test/spec_rack_content_length.rb
rack-1.1.3 test/spec_rack_content_length.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/rack-1.1.2/test/spec_rack_content_length.rb
rack-1.1.2 test/spec_rack_content_length.rb
rack-1.1.1 test/spec_rack_content_length.rb
rack-1.1.1.pre test/spec_rack_content_length.rb
eac-rack-1.1.1 test/spec_rack_content_length.rb
nbudin-castronaut-0.7.5 vendor/rack/test/spec_rack_content_length.rb