diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-10-12 23:23:02 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-10-12 23:23:02 -0500 |
commit | 610e94c097fcc41aaf11bf5ddd45898718aeeb55 (patch) | |
tree | fb56f356376ec37fb16b2010438201a4cdd9327e /activesupport/lib | |
parent | 29b280666b6a8216a46b8349fa76c85f5b5dcc55 (diff) | |
download | rails-610e94c097fcc41aaf11bf5ddd45898718aeeb55.tar.gz rails-610e94c097fcc41aaf11bf5ddd45898718aeeb55.tar.bz2 rails-610e94c097fcc41aaf11bf5ddd45898718aeeb55.zip |
Rewrite AS::TestCase setup/teardown as a single callback chain
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/testing/setup_and_teardown.rb | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index 97773dc2c0..b738ef334c 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -6,7 +6,7 @@ module ActiveSupport extend ClassMethods include ActiveSupport::Callbacks - define_callbacks :setup, :teardown + define_callbacks :test if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions include ForMiniTest @@ -18,11 +18,15 @@ module ActiveSupport module ClassMethods def setup(*args, &block) - set_callback(:setup, *args, &block) + set_callback(:test, :before, *args, &block) end def teardown(*args, &block) - set_callback(:teardown, *args, &block) + set_callback(:test, :after, *args, &block) + end + + def wrap(*args, &block) + set_callback(:test, :around, *args, &block) end end @@ -30,16 +34,15 @@ module ActiveSupport def run(runner) result = '.' begin - run_callbacks :setup - result = super + run_callbacks :test do + begin + result = super + rescue Exception => e + result = runner.puke(self.class, self.name, e) + end + end rescue Exception => e result = runner.puke(self.class, self.name, e) - ensure - begin - run_callbacks :teardown, :enumerator => :reverse_each - rescue Exception => e - result = runner.puke(self.class, self.name, e) - end end result end @@ -67,27 +70,27 @@ module ActiveSupport @_result = result begin begin - run_callbacks :setup - setup - __send__(@method_name) - mocha_verify(assertion_counter) if using_mocha - rescue Mocha::ExpectationError => e - add_failure(e.message, e.backtrace) + run_callbacks :test do + begin + setup + __send__(@method_name) + mocha_verify(assertion_counter) if using_mocha + rescue Mocha::ExpectationError => e + add_failure(e.message, e.backtrace) + rescue Test::Unit::AssertionFailedError => e + add_failure(e.message, e.backtrace) + rescue Exception => e + raise if PASSTHROUGH_EXCEPTIONS.include?(e.class) + add_error(e) + ensure + teardown + end + end rescue Test::Unit::AssertionFailedError => e add_failure(e.message, e.backtrace) rescue Exception => e raise if PASSTHROUGH_EXCEPTIONS.include?(e.class) add_error(e) - ensure - begin - teardown - run_callbacks :teardown, :enumerator => :reverse_each - rescue Test::Unit::AssertionFailedError => e - add_failure(e.message, e.backtrace) - rescue Exception => e - raise if PASSTHROUGH_EXCEPTIONS.include?(e.class) - add_error(e) - end end ensure mocha_teardown if using_mocha |