Sha256: a637783b2975f9be28e9533b4917309cd6820a85b7ac343f0b21a0a0b59a4e08

Contents?: true

Size: 1.33 KB

Versions: 55

Compression:

Stored size: 1.33 KB

Contents

require 'minitest/autorun'
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

  it "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].must_equal 200
      resp[1].must_equal "Content-type" => "test/plain", "Content-length" => "3"
      resp[2].to_enum.to_a.must_equal ["foo"]
    end
  end

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

    resp[0].must_equal 200
    resp[1].must_equal "Content-type" => "test/plain", "Content-length" => "3"
    resp[2].to_enum.to_a.must_equal []
  end

  it "close the body when it is removed" do
    resp, body = test_response("REQUEST_METHOD" => "HEAD")
    resp[0].must_equal 200
    resp[1].must_equal "Content-type" => "test/plain", "Content-length" => "3"
    resp[2].to_enum.to_a.must_equal []
    body.wont_be :closed?
    resp[2].close
    body.must_be :closed?
  end
end

Version data entries

55 entries across 53 versions & 14 rubygems

Version Path
rack-2.0.9.4 test/spec_head.rb
rack-2.0.9.3 test/spec_head.rb
rack-2.0.9.2 test/spec_head.rb
rack-2.0.9.1 test/spec_head.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-2.0.5/test/spec_head.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/test/spec_head.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/test/spec_head.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/test/spec_head.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/test/spec_head.rb
rack-2.0.9 test/spec_head.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rack-2.0.8/test/spec_head.rb
rack-2.0.8 test/spec_head.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_head.rb
tdiary-5.1.0 vendor/bundle/gems/rack-2.0.7/test/spec_head.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_head.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/test/spec_head.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/test/spec_head.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_head.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_head.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_head.rb