Sha256: 6ce527757af320c1474c25a7099001b07d528ee472b57183b31da1878a1a9003

Contents?: true

Size: 1.31 KB

Versions: 29

Compression:

Stored size: 1.31 KB

Contents

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

  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"})
      resp[2].to_enum.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"})
    resp[2].to_enum.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"})
    resp[2].to_enum.to_a.should.equal([])
    body.should.be.closed
  end
end

Version data entries

29 entries across 24 versions & 10 rubygems

Version Path
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/rack-1.5.5/test/spec_head.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/rack-1.5.5/test/spec_head.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/rack-1.5.5/test/spec_head.rb
rack-1.5.5 test/spec_head.rb
rack-1.5.4 test/spec_head.rb
rack-1.5.3 test/spec_head.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/test/spec_head.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/test/spec_head.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/test/spec_head.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/test/spec_head.rb
nanumfont-rails-0.1 vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/test/spec_head.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/test/spec_head.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rack-1.5.2/test/spec_head.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rack-1.5.2/test/spec_head.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/rack-1.5.2/test/spec_head.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/rack-1.5.2/test/spec_head.rb
challah-1.0.0 vendor/bundle/gems/rack-1.5.2/test/spec_head.rb
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/rack-1.5.2/test/spec_head.rb
torquebox-console-0.2.5 vendor/bundle/ruby/1.8/gems/rack-1.5.2/test/spec_head.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/rack-1.5.2/test/spec_head.rb