2009-12-19 03:16:58 +01:00
|
|
|
require 'rack/head'
|
|
|
|
require 'rack/mock'
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
describe Rack::Head do
|
2009-12-19 03:16:58 +01:00
|
|
|
def test_response(headers = {})
|
|
|
|
app = lambda { |env| [200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]] }
|
|
|
|
request = Rack::MockRequest.env_for("/", headers)
|
|
|
|
response = Rack::Head.new(app).call(request)
|
|
|
|
|
|
|
|
return response
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "pass GET, POST, PUT, DELETE, OPTIONS, TRACE requests" do
|
2009-12-19 03:16:58 +01:00
|
|
|
%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].should.equal(["foo"])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "remove body from HEAD requests" do
|
2009-12-19 03:16:58 +01:00
|
|
|
resp = test_response("REQUEST_METHOD" => "HEAD")
|
|
|
|
|
|
|
|
resp[0].should.equal(200)
|
|
|
|
resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
|
|
|
|
resp[2].should.equal([])
|
|
|
|
end
|
|
|
|
end
|