spec_handler.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. require 'rack/handler'
  2. class Rack::Handler::Lobster; end
  3. class RockLobster; end
  4. describe Rack::Handler do
  5. it "has registered default handlers" do
  6. Rack::Handler.get('cgi').should.equal Rack::Handler::CGI
  7. Rack::Handler.get('webrick').should.equal Rack::Handler::WEBrick
  8. begin
  9. Rack::Handler.get('fastcgi').should.equal Rack::Handler::FastCGI
  10. rescue LoadError
  11. end
  12. begin
  13. Rack::Handler.get('mongrel').should.equal Rack::Handler::Mongrel
  14. rescue LoadError
  15. end
  16. end
  17. should "raise LoadError if handler doesn't exist" do
  18. lambda {
  19. Rack::Handler.get('boom')
  20. }.should.raise(LoadError)
  21. end
  22. should "get unregistered, but already required, handler by name" do
  23. Rack::Handler.get('Lobster').should.equal Rack::Handler::Lobster
  24. end
  25. should "register custom handler" do
  26. Rack::Handler.register('rock_lobster', 'RockLobster')
  27. Rack::Handler.get('rock_lobster').should.equal RockLobster
  28. end
  29. should "not need registration for properly coded handlers even if not already required" do
  30. begin
  31. $LOAD_PATH.push File.expand_path('../unregistered_handler', __FILE__)
  32. Rack::Handler.get('Unregistered').should.equal Rack::Handler::Unregistered
  33. lambda {
  34. Rack::Handler.get('UnRegistered')
  35. }.should.raise LoadError
  36. Rack::Handler.get('UnregisteredLongOne').should.equal Rack::Handler::UnregisteredLongOne
  37. ensure
  38. $LOAD_PATH.delete File.expand_path('../unregistered_handler', __FILE__)
  39. end
  40. end
  41. should "allow autoloaded handlers to be registered properly while being loaded" do
  42. path = File.expand_path('../registering_handler', __FILE__)
  43. begin
  44. $LOAD_PATH.push path
  45. Rack::Handler.get('registering_myself').should.equal Rack::Handler::RegisteringMyself
  46. ensure
  47. $LOAD_PATH.delete path
  48. end
  49. end
  50. end