Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: test/fcgi_dispatcher_test.rb
- ===================================================================
- --- test/fcgi_dispatcher_test.rb (revision 4846)
- +++ test/fcgi_dispatcher_test.rb (working copy)
- @@ -1,11 +1,10 @@
- -$:.unshift File.dirname(__FILE__) + "/../lib"
- +require File.dirname(__FILE__) + "/abstract_unit"
- +
- $:.unshift File.dirname(__FILE__) + "/mocks"
- -require 'test/unit'
- require 'stringio'
- require 'fcgi_handler'
- -RAILS_ROOT = File.dirname(__FILE__) if !defined?(RAILS_ROOT)
- class RailsFCGIHandler
- attr_reader :exit_code
- @@ -34,7 +33,7 @@
- def reload!
- @reloaded = true
- end
- -
- +
- alias_method :old_run_gc!, :run_gc!
- def run_gc!
- @gc_runs ||= 0
- @@ -53,6 +52,52 @@
- Dispatcher.raise_exception = nil
- end
- + def test_process_restart
- + delegate_methods_to_mock!(RailsFCGIHandler, :restart!, :close_connection) do
- + fcgi = mock()
- + fcgi.expects(:close_connection)
- + fcgi.expects(:restart!)
- +
- + @handler.mock = fcgi
- + @handler.stubs(:when_ready).returns(:restart)
- + @handler.process!
- + end
- + end
- +
- + def test_process_exit
- + delegate_method_to_mock!(RailsFCGIHandler, :close_connection) do
- + fcgi = mock()
- + fcgi.expects(:close_connection)
- +
- + @handler.mock = fcgi
- + @handler.stubs(:when_ready).returns(:exit)
- + @handler.process!
- + end
- + end
- +
- + def test_process_breakpoint
- + delegate_methods_to_mock!(RailsFCGIHandler, :breakpoint!, :close_connection) do
- + fcgi = mock()
- + fcgi.expects(:close_connection)
- + fcgi.expects(:breakpoint!)
- +
- + @handler.mock = fcgi
- + @handler.stubs(:when_ready).returns(:breakpoint)
- + @handler.process!
- + end
- + end
- +
- + def test_process_with_system_exit_exception
- + delegate_method_to_mock!(RailsFCGIHandler, :dispatcher_log) do
- + fcgi = mock()
- + fcgi.expects(:dispatcher_log).with(:info, "terminated by explicit exit")
- +
- + @handler.mock = fcgi
- + @handler.stubs(:process_request).raises(SystemExit)
- + @handler.process!
- + end
- + end
- +
- def test_uninterrupted_processing
- @handler.process!
- assert_nil @handler.exit_code
- Index: test/abstract_unit.rb
- ===================================================================
- --- test/abstract_unit.rb (revision 0)
- +++ test/abstract_unit.rb (revision 0)
- @@ -0,0 +1,42 @@
- +$:.unshift File.dirname(__FILE__) + "/../lib"
- +
- +require 'test/unit'
- +require 'rubygems'
- +require 'mocha'
- +require 'stubba'
- +
- +RAILS_ROOT = File.dirname(__FILE__) if !defined?(RAILS_ROOT)
- +
- +class Test::Unit::TestCase
- + def delegate_methods_to_mock!(klass, *methods)
- + klass.send(:attr_writer, :mock) unless klass.respond_to? :mock=
- + methods.each {|m| redefine_method_using_mock! klass, m }
- + yield
- + methods.each {|m| reset_method_using_mock! klass, m }
- + end
- +
- + def delegate_method_to_mock!(klass, method)
- + klass.send(:attr_writer, :mock) unless klass.respond_to? :mock=
- + redefine_method_using_mock! klass, method
- + yield
- + reset_method_using_mock! klass, method
- + end
- +
- + def redefine_method_using_mock!(klass, method)
- + klass.send(:alias_method, "nonmocked_#{method.to_s}", method.to_s)
- +
- + klass.send(:define_method, method,
- + Proc.new {|*args|
- + @mock.send(method, *args)
- + }
- + )
- + end
- +
- + def reset_method_using_mock!(klass, method)
- + klass.send(:define_method, method,
- + Proc.new {|*args|
- + send("nonmocked_#{method.to_s}", *args)
- + }
- + )
- + end
- +end
- \ No newline at end of file
- Index: lib/fcgi_handler.rb
- ===================================================================
- --- lib/fcgi_handler.rb (revision 4846)
- +++ lib/fcgi_handler.rb (working copy)
- @@ -89,7 +89,7 @@
- end
- - private
- + protected
- def logger
- @logger ||= Logger.new(@log_file_path)
- end
Add Comment
Please, Sign In to add comment