From aae37bb4f7edd6a1820e420a60560369c6064f33 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 19 Jan 2008 02:44:45 +0000 Subject: Extract ActiveSupport::Callbacks from Active Record, test case setup and teardown, and ActionController::Dispatcher. Closes #10727. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8664 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../active_support/testing/setup_and_teardown.rb | 50 ++-------------------- 1 file changed, 4 insertions(+), 46 deletions(-) (limited to 'activesupport/lib/active_support/testing') diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index 1639462fae..b2a937edd0 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -2,7 +2,8 @@ module ActiveSupport module Testing module SetupAndTeardown def self.included(base) - base.extend ClassMethods + base.send :include, ActiveSupport::Callbacks + base.define_callbacks :setup, :teardown begin require 'mocha' @@ -12,38 +13,6 @@ module ActiveSupport end end - module ClassMethods - def setup(*method_names, &block) - method_names << block if block_given? - (@setup_callbacks ||= []).concat method_names - end - - def teardown(*method_names, &block) - method_names << block if block_given? - (@teardown_callbacks ||= []).concat method_names - end - - def setup_callback_chain - @setup_callbacks ||= [] - - if superclass.respond_to?(:setup_callback_chain) - superclass.setup_callback_chain + @setup_callbacks - else - @setup_callbacks - end - end - - def teardown_callback_chain - @teardown_callbacks ||= [] - - if superclass.respond_to?(:teardown_callback_chain) - superclass.teardown_callback_chain + @teardown_callbacks - else - @teardown_callbacks - end - end - end - # This redefinition is unfortunate but test/unit shows us no alternative. def run_with_callbacks(result) #:nodoc: return if @method_name.to_s == "default_test" @@ -63,7 +32,7 @@ module ActiveSupport ensure begin teardown - run_callbacks :teardown, :reverse_each + run_callbacks :teardown, :enumerator => :reverse_each rescue Test::Unit::AssertionFailedError => e add_failure(e.message, e.backtrace) rescue *Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS @@ -98,7 +67,7 @@ module ActiveSupport ensure begin teardown - run_callbacks :teardown, :reverse_each + run_callbacks :teardown, :enumerator => :reverse_each rescue Test::Unit::AssertionFailedError => e add_failure(e.message, e.backtrace) rescue StandardError, ScriptError @@ -111,17 +80,6 @@ module ActiveSupport result.add_run yield(Test::Unit::TestCase::FINISHED, name) end - - protected - def run_callbacks(kind, enumerator = :each) - self.class.send("#{kind}_callback_chain").send(enumerator) do |callback| - case callback - when Proc; callback.call(self) - when String, Symbol; send!(callback) - else raise ArgumentError, "Unrecognized callback #{callback.inspect}" - end - end - end end end end -- cgit v1.2.3