aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-06-10 03:46:23 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-06-10 14:01:16 -0700
commit34c51c9e8f758a5fc892e654b6ca1ad8b86d1b3a (patch)
tree821dca1e692cf10ea6629b0d1a9b77aebcb793be /activesupport/lib/active_support
parentf5cbad21ac09822a61d6326cbadea16bbe86b623 (diff)
downloadrails-34c51c9e8f758a5fc892e654b6ca1ad8b86d1b3a.tar.gz
rails-34c51c9e8f758a5fc892e654b6ca1ad8b86d1b3a.tar.bz2
rails-34c51c9e8f758a5fc892e654b6ca1ad8b86d1b3a.zip
Rubinious: setup/teardown override for miniunit
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/testing/setup_and_teardown.rb38
1 files changed, 31 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb
index ed8e34510a..21d71eb92a 100644
--- a/activesupport/lib/active_support/testing/setup_and_teardown.rb
+++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb
@@ -10,19 +10,43 @@ module ActiveSupport
end
def self.included(base)
- base.send :include, ActiveSupport::Callbacks
- base.define_callbacks :setup, :teardown
+ base.class_eval do
+ include ActiveSupport::Callbacks
+ define_callbacks :setup, :teardown
+ if defined?(::Mini)
+ alias_method :run, :run_with_callbacks_and_miniunit
+ else
+ begin
+ require 'mocha'
+ alias_method :run, :run_with_callbacks_and_mocha
+ rescue LoadError
+ alias_method :run, :run_with_callbacks_and_testunit
+ end
+ end
+ end
+ end
+
+ def run_with_callbacks_and_miniunit(runner)
+ result = '.'
begin
- require 'mocha'
- base.alias_method_chain :run, :callbacks_and_mocha
- rescue LoadError
- base.alias_method_chain :run, :callbacks
+ run_callbacks :setup
+ result = super
+ rescue Exception => e
+ result = runner.puke(self.class, self.name, e)
+ ensure
+ begin
+ teardown
+ run_callbacks :teardown, :enumerator => :reverse_each
+ rescue Exception => e
+ result = runner.puke(self.class, self.name, e)
+ end
end
+ result
end
# This redefinition is unfortunate but test/unit shows us no alternative.
- def run_with_callbacks(result) #:nodoc:
+ def run_with_callbacks_and_testunit(result) #:nodoc:
return if @method_name.to_s == "default_test"
yield(Test::Unit::TestCase::STARTED, name)