Skip to content

Commit

Permalink
Revert "Rewrite AS::TestCase setup/teardown as a single callback chain"
Browse files Browse the repository at this point in the history
This reverts commit 610e94c.
  • Loading branch information
jeremy committed Oct 14, 2009
1 parent d5d2426 commit efdc062
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions activesupport/lib/active_support/testing/setup_and_teardown.rb
Expand Up @@ -6,7 +6,7 @@ def self.included(base)
extend ClassMethods

include ActiveSupport::Callbacks
define_callbacks :test
define_callbacks :setup, :teardown

if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions
include ForMiniTest
Expand All @@ -18,31 +18,28 @@ def self.included(base)

module ClassMethods
def setup(*args, &block)
set_callback(:test, :before, *args, &block)
set_callback(:setup, *args, &block)
end

def teardown(*args, &block)
set_callback(:test, :after, *args, &block)
end

def wrap(*args, &block)
set_callback(:test, :around, *args, &block)
set_callback(:teardown, *args, &block)
end
end

module ForMiniTest
def run(runner)
result = '.'
begin
run_callbacks :test do
begin
result = super
rescue Exception => e
result = runner.puke(self.class, self.name, e)
end
end
run_callbacks :setup
result = super
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
Expand Down Expand Up @@ -70,27 +67,27 @@ def run(result)
@_result = result
begin
begin
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
run_callbacks :setup
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
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
Expand Down

0 comments on commit efdc062

Please sign in to comment.