Sha256: 3c58b37e473ba7a7e91d33c9e98590b41de53bf220f22636048ed90e6df12389

Contents?: true

Size: 1.41 KB

Versions: 39

Compression:

Stored size: 1.41 KB

Contents

require 'enumerator'
require 'rack/head'
require 'rack/lint'
require 'rack/mock'

describe Rack::Head do

  def test_response(headers = {})
    body = StringIO.new "foo"
    app = lambda do |env|
      [200, {"Content-type" => "test/plain", "Content-length" => "3"}, body]
    end
    request = Rack::MockRequest.env_for("/", headers)
    response = Rack::Lint.new(Rack::Head.new(app)).call(request)

    return response, body
  end

  def enum
    defined?(Enumerator) ? Enumerator : Enumerable::Enumerator
  end

  should "pass GET, POST, PUT, DELETE, OPTIONS, TRACE requests" do
    %w[GET POST PUT DELETE OPTIONS TRACE].each do |type|
      resp, _ = test_response("REQUEST_METHOD" => type)

      resp[0].should.equal(200)
      resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
      enum.new(resp[2]).to_a.should.equal(["foo"])
    end
  end

  should "remove body from HEAD requests" do
    resp, _ = test_response("REQUEST_METHOD" => "HEAD")

    resp[0].should.equal(200)
    resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
    enum.new(resp[2]).to_a.should.equal([])
  end

  should "close the body when it is removed" do
    resp, body = test_response("REQUEST_METHOD" => "HEAD")
    resp[0].should.equal(200)
    resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
    enum.new(resp[2]).to_a.should.equal([])
    body.should.be.closed
  end
end

Version data entries

39 entries across 34 versions & 13 rubygems

Version Path
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_head.rb
rack-1.4.7 test/spec_head.rb
rack-1.4.6 test/spec_head.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/test/spec_head.rb
swipe-rails-0.0.5 vendor/bundle/gems/rack-1.4.5/test/spec_head.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_head.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_head.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_head.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_head.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/rack-1.4.5/test/spec_head.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/rack-1.4.5/test/spec_head.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/rack-1.4.5/test/spec_head.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/rack-1.4.5/test/spec_head.rb
challah-1.0.0.beta3 vendor/bundle/gems/rack-1.4.5/test/spec_head.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_head.rb
challah-1.0.0.beta2 vendor/bundle/gems/rack-1.4.5/test/spec_head.rb
challah-1.0.0.beta vendor/bundle/gems/rack-1.4.5/test/spec_head.rb
challah-1.0.0.beta vendor/bundle/gems/rack-1.4.3/test/spec_head.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_head.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_head.rb