aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/testing')
-rw-r--r--activesupport/lib/active_support/testing/setup_and_teardown.rb50
1 files changed, 4 insertions, 46 deletions
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