spec_head.rb 929 B

123456789101112131415161718192021222324252627282930
  1. require 'rack/head'
  2. require 'rack/mock'
  3. describe Rack::Head do
  4. def test_response(headers = {})
  5. app = lambda { |env| [200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]] }
  6. request = Rack::MockRequest.env_for("/", headers)
  7. response = Rack::Head.new(app).call(request)
  8. return response
  9. end
  10. should "pass GET, POST, PUT, DELETE, OPTIONS, TRACE requests" do
  11. %w[GET POST PUT DELETE OPTIONS TRACE].each do |type|
  12. resp = test_response("REQUEST_METHOD" => type)
  13. resp[0].should.equal(200)
  14. resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
  15. resp[2].should.equal(["foo"])
  16. end
  17. end
  18. should "remove body from HEAD requests" do
  19. resp = test_response("REQUEST_METHOD" => "HEAD")
  20. resp[0].should.equal(200)
  21. resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
  22. resp[2].should.equal([])
  23. end
  24. end