PageRenderTime 29ms CodeModel.GetById 16ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/rack-1.5.2/test/spec_head.rb

https://github.com/delowong/logstash
Ruby | 43 lines | 35 code | 8 blank | 0 comment | 0 complexity | e13ab7e43bdfe4fdec129080c7ac15d8 MD5 | raw file
 1require 'rack/head'
 2require 'rack/lint'
 3require 'rack/mock'
 4
 5describe Rack::Head do
 6
 7  def test_response(headers = {})
 8    body = StringIO.new "foo"
 9    app = lambda do |env|
10      [200, {"Content-type" => "test/plain", "Content-length" => "3"}, body]
11    end
12    request = Rack::MockRequest.env_for("/", headers)
13    response = Rack::Lint.new(Rack::Head.new(app)).call(request)
14
15    return response, body
16  end
17
18  should "pass GET, POST, PUT, DELETE, OPTIONS, TRACE requests" do
19    %w[GET POST PUT DELETE OPTIONS TRACE].each do |type|
20      resp, _ = test_response("REQUEST_METHOD" => type)
21
22      resp[0].should.equal(200)
23      resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
24      resp[2].to_enum.to_a.should.equal(["foo"])
25    end
26  end
27
28  should "remove body from HEAD requests" do
29    resp, _ = test_response("REQUEST_METHOD" => "HEAD")
30
31    resp[0].should.equal(200)
32    resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
33    resp[2].to_enum.to_a.should.equal([])
34  end
35
36  should "close the body when it is removed" do
37    resp, body = test_response("REQUEST_METHOD" => "HEAD")
38    resp[0].should.equal(200)
39    resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
40    resp[2].to_enum.to_a.should.equal([])
41    body.should.be.closed
42  end
43end