From 139b92495fa7697cdd619c549d4c7b263562b761 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 5 Jan 2008 13:34:15 +0000 Subject: * Continue evolution toward ActiveSupport::TestCase and friends. #10679 [Josh Peek] * TestCase: introduce declared setup and teardown callbacks. Pass a list of methods and an optional block to call before setup or after teardown. Setup callbacks are run in the order declared; teardown callbacks are run in reverse. [Jeremy Kemper] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8570 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/test_case.rb | 32 +++++++++--------------- actionpack/lib/action_controller/test_process.rb | 1 + 2 files changed, 13 insertions(+), 20 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 84610c34c0..431876a72e 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -10,7 +10,16 @@ module ActionController end class TestCase < ActiveSupport::TestCase + module RaiseActionExceptions + def rescue_action(e) + raise e + end + end + + setup :setup_controller_request_and_response + @@controller_class = nil + class << self def tests(controller_class) self.controller_class = controller_class @@ -25,7 +34,7 @@ module ActionController if current_controller_class = read_inheritable_attribute(:controller_class) current_controller_class else - self.controller_class= determine_default_controller_class(name) + self.controller_class = determine_default_controller_class(name) end end @@ -36,31 +45,14 @@ module ActionController end def prepare_controller_class(new_class) - new_class.class_eval do - def rescue_action(e) - raise e - end - end + new_class.send :include, RaiseActionExceptions end end - def setup_with_controller + def setup_controller_request_and_response @controller = self.class.controller_class.new @request = TestRequest.new @response = TestResponse.new end - alias_method :setup, :setup_with_controller - - def self.method_added(method) - if method.to_s == 'setup' - unless method_defined?(:setup_without_controller) - alias_method :setup_without_controller, :setup - define_method(:setup) do - setup_with_controller - setup_without_controller - end - end - end - end end end diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index 4cbb695f4c..ba23f012da 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -1,4 +1,5 @@ require 'action_controller/assertions' +require 'action_controller/test_case' module ActionController #:nodoc: class Base -- cgit v1.2.3