require 'abstract_unit' uses_mocha 'dispatcher tests' do require 'action_controller/dispatcher' class DispatcherTest < Test::Unit::TestCase Dispatcher = ActionController::Dispatcher def setup @output = StringIO.new ENV['REQUEST_METHOD'] = 'GET' # Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks Dispatcher.instance_variable_set("@prepare_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new) Dispatcher.instance_variable_set("@before_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new) Dispatcher.instance_variable_set("@after_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new) Dispatcher.stubs(:require_dependency) @dispatcher = Dispatcher.new(@output) end def teardown ENV.delete 'REQUEST_METHOD' end def test_clears_dependencies_after_dispatch_if_in_loading_mode ActionController::Routing::Routes.expects(:reload).once ActiveSupport::Dependencies.expects(:clear).once dispatch(@output, false) end def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode ActionController::Routing::Routes.expects(:reload).never ActiveSupport::Dependencies.expects(:clear).never dispatch end # Stub out dispatch error logger class << Dispatcher def log_failsafe_exception(status, exception); end end def test_failsafe_response CGI.expects(:new).raises('some multipart parsing failure') Dispatcher.expects(:log_failsafe_exception) assert_nothing_raised { dispatch } assert_equal "Status: 400 Bad Request\r\nContent-Type: text/html\r\n\r\n