spec_thin.rb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. begin
  2. require 'rack/handler/thin'
  3. require File.expand_path('../testrequest', __FILE__)
  4. require 'timeout'
  5. describe Rack::Handler::Thin do
  6. extend TestRequest::Helpers
  7. @app = Rack::Lint.new(TestRequest.new)
  8. @server = nil
  9. Thin::Logging.silent = true
  10. @thread = Thread.new do
  11. Rack::Handler::Thin.run(@app, :Host => @host='127.0.0.1', :Port => @port=9204) do |server|
  12. @server = server
  13. end
  14. end
  15. Thread.pass until @server && @server.running?
  16. should "respond" do
  17. GET("/")
  18. response.should.not.be.nil
  19. end
  20. should "be a Thin" do
  21. GET("/")
  22. status.should.equal 200
  23. response["SERVER_SOFTWARE"].should =~ /thin/
  24. response["HTTP_VERSION"].should.equal "HTTP/1.1"
  25. response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
  26. response["SERVER_PORT"].should.equal "9204"
  27. response["SERVER_NAME"].should.equal "127.0.0.1"
  28. end
  29. should "have rack headers" do
  30. GET("/")
  31. response["rack.version"].should.equal [1,0]
  32. response["rack.multithread"].should.equal false
  33. response["rack.multiprocess"].should.equal false
  34. response["rack.run_once"].should.equal false
  35. end
  36. should "have CGI headers on GET" do
  37. GET("/")
  38. response["REQUEST_METHOD"].should.equal "GET"
  39. response["REQUEST_PATH"].should.equal "/"
  40. response["PATH_INFO"].should.be.equal "/"
  41. response["QUERY_STRING"].should.equal ""
  42. response["test.postdata"].should.equal ""
  43. GET("/test/foo?quux=1")
  44. response["REQUEST_METHOD"].should.equal "GET"
  45. response["REQUEST_PATH"].should.equal "/test/foo"
  46. response["PATH_INFO"].should.equal "/test/foo"
  47. response["QUERY_STRING"].should.equal "quux=1"
  48. end
  49. should "have CGI headers on POST" do
  50. POST("/", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
  51. status.should.equal 200
  52. response["REQUEST_METHOD"].should.equal "POST"
  53. response["REQUEST_PATH"].should.equal "/"
  54. response["QUERY_STRING"].should.equal ""
  55. response["HTTP_X_TEST_HEADER"].should.equal "42"
  56. response["test.postdata"].should.equal "rack-form-data=23"
  57. end
  58. should "support HTTP auth" do
  59. GET("/test", {:user => "ruth", :passwd => "secret"})
  60. response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
  61. end
  62. should "set status" do
  63. GET("/test?secret")
  64. status.should.equal 403
  65. response["rack.url_scheme"].should.equal "http"
  66. end
  67. @server.stop!
  68. @thread.kill
  69. end
  70. rescue LoadError
  71. $stderr.puts "Skipping Rack::Handler::Thin tests (Thin is required). `gem install thin` and try again."
  72. end