/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

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