aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-01-19 02:44:45 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-01-19 02:44:45 +0000
commitaae37bb4f7edd6a1820e420a60560369c6064f33 (patch)
tree5642ff690036cac09bc697a0798dd984128d6e73 /activesupport/lib/active_support/testing
parent3ffdfa84fc1f9bebc578fe957646af5f194ca625 (diff)
downloadrails-aae37bb4f7edd6a1820e420a60560369c6064f33.tar.gz
rails-aae37bb4f7edd6a1820e420a60560369c6064f33.tar.bz2
rails-aae37bb4f7edd6a1820e420a60560369c6064f33.zip
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
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