Permalink
Browse files

dispatcher test cosmetics

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4847 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent c4d2691 commit 92f1e26a1c9f48ac575414976012d6dfa127bdac @jeremy jeremy committed Aug 29, 2006
Showing with 15 additions and 15 deletions.
  1. +15 −15 railties/test/dispatcher_test.rb
@@ -24,30 +24,34 @@ class DispatcherTest < Test::Unit::TestCase
def setup
@output = StringIO.new
ENV['REQUEST_METHOD'] = "GET"
+
Dispatcher.send(:preparation_callbacks).clear
Dispatcher.send(:preparation_callbacks_run=, false)
+
+ Object.const_set :ApplicationController, nil
end
def teardown
+ Object.send :remove_const, :ApplicationController
ENV['REQUEST_METHOD'] = nil
end
def test_ac_subclasses_cleared_on_reset
Object.class_eval(ACTION_CONTROLLER_DEF)
- assert_equal 1, ActionController::Base.subclasses.length
+ assert_subclasses 1, ActionController::Base
dispatch
GC.start # force the subclass to be collected
- assert_equal 0, ActionController::Base.subclasses.length
+ assert_subclasses 0, ActionController::Base
end
def test_am_subclasses_cleared_on_reset
Object.class_eval(ACTION_MAILER_DEF)
- assert_equal 1, ActionMailer::Base.subclasses.length
+ assert_subclasses 1, ActionMailer::Base
dispatch
GC.start # force the subclass to be collected
- assert_equal 0, ActionMailer::Base.subclasses.length
+ assert_subclasses 0, ActionMailer::Base
end
@@ -78,17 +82,14 @@ def test_bad_multipart_request
[EMPTY_CONTENT, CONTENT_LENGTH_MISMATCH, NONINTEGER_CONTENT_LENGTH].each do |bad_request|
$stdin = StringIO.new(bad_request)
output = StringIO.new
- assert_nothing_raised do
- Dispatcher.dispatch(nil, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output)
- end
+ assert_nothing_raised { dispatch output }
assert_equal "Status: 400 Bad Request\r\n", output.string
end
ensure
$stdin = old_stdin
end
def test_preparation_callbacks
- Object.const_set :ApplicationController, nil
old_mechanism = Dependencies.mechanism
a = b = c = nil
@@ -117,25 +118,24 @@ def test_preparation_callbacks
assert_equal nil, a || b || c
ensure
Dependencies.mechanism = old_mechanism
- Object.send :remove_const, :ApplicationController
end
def test_to_prepare_with_identifier_replaces
- Object.const_set :ApplicationController, nil
-
a = b = nil
Dispatcher.to_prepare(:unique_id) { a = b = 1 }
Dispatcher.to_prepare(:unique_id) { a = 2 }
Dispatcher.send :prepare_application
assert_equal 2, a
assert_equal nil, b
- ensure
- Object.send :remove_const, :ApplicationController
end
private
- def dispatch
- Dispatcher.dispatch(nil, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, @output)
+ def dispatch(output = @output)
+ Dispatcher.dispatch(nil, {}, output)
+ end
+
+ def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
+ assert_equal howmany, klass.subclasses.size, message
end
end

0 comments on commit 92f1e26

Please sign in to comment.