spec_showstatus.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. require 'rack/showstatus'
  2. require 'rack/mock'
  3. describe Rack::ShowStatus do
  4. should "provide a default status message" do
  5. req = Rack::MockRequest.new(
  6. Rack::ShowStatus.new(lambda{|env|
  7. [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
  8. }))
  9. res = req.get("/", :lint => true)
  10. res.should.be.not_found
  11. res.should.be.not.empty
  12. res["Content-Type"].should.equal("text/html")
  13. res.should =~ /404/
  14. res.should =~ /Not Found/
  15. end
  16. should "let the app provide additional information" do
  17. req = Rack::MockRequest.new(
  18. Rack::ShowStatus.new(
  19. lambda{|env|
  20. env["rack.showstatus.detail"] = "gone too meta."
  21. [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
  22. }))
  23. res = req.get("/", :lint => true)
  24. res.should.be.not_found
  25. res.should.be.not.empty
  26. res["Content-Type"].should.equal("text/html")
  27. res.should =~ /404/
  28. res.should =~ /Not Found/
  29. res.should =~ /too meta/
  30. end
  31. should "not replace existing messages" do
  32. req = Rack::MockRequest.new(
  33. Rack::ShowStatus.new(
  34. lambda{|env|
  35. [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
  36. }))
  37. res = req.get("/", :lint => true)
  38. res.should.be.not_found
  39. res.body.should == "foo!"
  40. end
  41. should "pass on original headers" do
  42. headers = {"WWW-Authenticate" => "Basic blah"}
  43. req = Rack::MockRequest.new(
  44. Rack::ShowStatus.new(lambda{|env| [401, headers, []] }))
  45. res = req.get("/", :lint => true)
  46. res["WWW-Authenticate"].should.equal("Basic blah")
  47. end
  48. should "replace existing messages if there is detail" do
  49. req = Rack::MockRequest.new(
  50. Rack::ShowStatus.new(
  51. lambda{|env|
  52. env["rack.showstatus.detail"] = "gone too meta."
  53. [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
  54. }))
  55. res = req.get("/", :lint => true)
  56. res.should.be.not_found
  57. res.should.be.not.empty
  58. res["Content-Type"].should.equal("text/html")
  59. res["Content-Length"].should.not.equal("4")
  60. res.should =~ /404/
  61. res.should =~ /too meta/
  62. res.body.should.not =~ /foo/
  63. end
  64. end