Guest User

Untitled

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. Index: test/fcgi_dispatcher_test.rb
  2. ===================================================================
  3. --- test/fcgi_dispatcher_test.rb (revision 4846)
  4. +++ test/fcgi_dispatcher_test.rb (working copy)
  5. @@ -1,11 +1,10 @@
  6. -$:.unshift File.dirname(__FILE__) + "/../lib"
  7. +require File.dirname(__FILE__) + "/abstract_unit"
  8. +
  9. $:.unshift File.dirname(__FILE__) + "/mocks"
  10.  
  11. -require 'test/unit'
  12. require 'stringio'
  13. require 'fcgi_handler'
  14.  
  15. -RAILS_ROOT = File.dirname(__FILE__) if !defined?(RAILS_ROOT)
  16.  
  17. class RailsFCGIHandler
  18. attr_reader :exit_code
  19. @@ -34,7 +33,7 @@
  20. def reload!
  21. @reloaded = true
  22. end
  23. -
  24. +
  25. alias_method :old_run_gc!, :run_gc!
  26. def run_gc!
  27. @gc_runs ||= 0
  28. @@ -53,6 +52,52 @@
  29. Dispatcher.raise_exception = nil
  30. end
  31.  
  32. + def test_process_restart
  33. + delegate_methods_to_mock!(RailsFCGIHandler, :restart!, :close_connection) do
  34. + fcgi = mock()
  35. + fcgi.expects(:close_connection)
  36. + fcgi.expects(:restart!)
  37. +
  38. + @handler.mock = fcgi
  39. + @handler.stubs(:when_ready).returns(:restart)
  40. + @handler.process!
  41. + end
  42. + end
  43. +
  44. + def test_process_exit
  45. + delegate_method_to_mock!(RailsFCGIHandler, :close_connection) do
  46. + fcgi = mock()
  47. + fcgi.expects(:close_connection)
  48. +
  49. + @handler.mock = fcgi
  50. + @handler.stubs(:when_ready).returns(:exit)
  51. + @handler.process!
  52. + end
  53. + end
  54. +
  55. + def test_process_breakpoint
  56. + delegate_methods_to_mock!(RailsFCGIHandler, :breakpoint!, :close_connection) do
  57. + fcgi = mock()
  58. + fcgi.expects(:close_connection)
  59. + fcgi.expects(:breakpoint!)
  60. +
  61. + @handler.mock = fcgi
  62. + @handler.stubs(:when_ready).returns(:breakpoint)
  63. + @handler.process!
  64. + end
  65. + end
  66. +
  67. + def test_process_with_system_exit_exception
  68. + delegate_method_to_mock!(RailsFCGIHandler, :dispatcher_log) do
  69. + fcgi = mock()
  70. + fcgi.expects(:dispatcher_log).with(:info, "terminated by explicit exit")
  71. +
  72. + @handler.mock = fcgi
  73. + @handler.stubs(:process_request).raises(SystemExit)
  74. + @handler.process!
  75. + end
  76. + end
  77. +
  78. def test_uninterrupted_processing
  79. @handler.process!
  80. assert_nil @handler.exit_code
  81. Index: test/abstract_unit.rb
  82. ===================================================================
  83. --- test/abstract_unit.rb (revision 0)
  84. +++ test/abstract_unit.rb (revision 0)
  85. @@ -0,0 +1,42 @@
  86. +$:.unshift File.dirname(__FILE__) + "/../lib"
  87. +
  88. +require 'test/unit'
  89. +require 'rubygems'
  90. +require 'mocha'
  91. +require 'stubba'
  92. +
  93. +RAILS_ROOT = File.dirname(__FILE__) if !defined?(RAILS_ROOT)
  94. +
  95. +class Test::Unit::TestCase
  96. + def delegate_methods_to_mock!(klass, *methods)
  97. + klass.send(:attr_writer, :mock) unless klass.respond_to? :mock=
  98. + methods.each {|m| redefine_method_using_mock! klass, m }
  99. + yield
  100. + methods.each {|m| reset_method_using_mock! klass, m }
  101. + end
  102. +
  103. + def delegate_method_to_mock!(klass, method)
  104. + klass.send(:attr_writer, :mock) unless klass.respond_to? :mock=
  105. + redefine_method_using_mock! klass, method
  106. + yield
  107. + reset_method_using_mock! klass, method
  108. + end
  109. +
  110. + def redefine_method_using_mock!(klass, method)
  111. + klass.send(:alias_method, "nonmocked_#{method.to_s}", method.to_s)
  112. +
  113. + klass.send(:define_method, method,
  114. + Proc.new {|*args|
  115. + @mock.send(method, *args)
  116. + }
  117. + )
  118. + end
  119. +
  120. + def reset_method_using_mock!(klass, method)
  121. + klass.send(:define_method, method,
  122. + Proc.new {|*args|
  123. + send("nonmocked_#{method.to_s}", *args)
  124. + }
  125. + )
  126. + end
  127. +end
  128. \ No newline at end of file
  129. Index: lib/fcgi_handler.rb
  130. ===================================================================
  131. --- lib/fcgi_handler.rb (revision 4846)
  132. +++ lib/fcgi_handler.rb (working copy)
  133. @@ -89,7 +89,7 @@
  134. end
  135.  
  136.  
  137. - private
  138. + protected
  139. def logger
  140. @logger ||= Logger.new(@log_file_path)
  141. end
Add Comment
Please, Sign In to add comment