diff options
author | James Tucker <raggi@google.com> | 2012-12-28 17:28:26 -0500 |
---|---|---|
committer | James Tucker <raggi@google.com> | 2012-12-28 17:28:26 -0500 |
commit | 224822439fedc19795f051949c598fc7f5970723 (patch) | |
tree | 09f359d57e130bc79090d1be3ed25ba770b91304 /test/spec_head.rb | |
parent | 531384f88e9930886d9f49dfb28ef2d476373c4a (diff) | |
download | rack-224822439fedc19795f051949c598fc7f5970723.tar.gz |
Rack::Head now conforms to body.close SPEC
Diffstat (limited to 'test/spec_head.rb')
-rw-r--r-- | test/spec_head.rb | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/test/spec_head.rb b/test/spec_head.rb index 289f5819..361c49b9 100644 --- a/test/spec_head.rb +++ b/test/spec_head.rb @@ -4,12 +4,27 @@ require 'rack/lint' require 'rack/mock' describe Rack::Head do + + @closable_body = Struct.new(:body, :closed) do + def each + yield body + end + + def close + self.closed = true + end + alias closed? closed + end + def test_response(headers = {}) - app = lambda { |env| [200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]] } + body = @closable_body.new("foo", false) + 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 + return response, body end def enum @@ -18,7 +33,7 @@ describe Rack::Head do 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, _ = test_response("REQUEST_METHOD" => type) resp[0].should.equal(200) resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"}) @@ -27,10 +42,18 @@ describe Rack::Head do end should "remove body from HEAD requests" do - resp = test_response("REQUEST_METHOD" => "HEAD") + 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 |