<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>activesupport/lib/active_support/testing/mocha_minitest_adapter.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,46 +1,40 @@
+require 'test/unit/testcase'
 require 'active_support/testing/setup_and_teardown'
 require 'active_support/testing/assertions'
 require 'active_support/testing/declarative'
 
-module ActiveSupport
-  # Prefer MiniTest with Test::Unit compatibility.
-  begin
-    require 'minitest/unit'
+begin
+  gem 'mocha', '&gt;= 0.9.0'
+  require 'mocha'
 
-    # Hack around the test/unit autorun.
-    autorun_enabled = MiniTest::Unit.send(:class_variable_get, '@@installed_at_exit')
-    if MiniTest::Unit.respond_to?(:disable_autorun)
-      MiniTest::Unit.disable_autorun
-    else
-      MiniTest::Unit.send(:class_variable_set, '@@installed_at_exit', false)
-    end
-    require 'test/unit'
-    MiniTest::Unit.send(:class_variable_set, '@@installed_at_exit', autorun_enabled)
+  if defined?(MiniTest)
+    require 'active_support/testing/mocha_minitest_adapter'
+  end
+rescue LoadError
+  # Fake Mocha::ExpectationError so we can rescue it in #run. Bleh.
+  Object.const_set :Mocha, Module.new
+  Mocha.const_set :ExpectationError, Class.new(StandardError)
+end
 
-    class TestCase &lt; ::Test::Unit::TestCase
+module ActiveSupport
+  class TestCase &lt; ::Test::Unit::TestCase
+    if defined? MiniTest
       Assertion = MiniTest::Assertion
-    end
-
-    # TODO: Figure out how to get the Rails::BacktraceFilter into minitest/unit
-  # Test::Unit compatibility.
-  rescue LoadError
-    require 'test/unit/testcase'
-    require 'active_support/testing/default'
-
-    if defined?(Rails)
-      require 'rails/backtrace_cleaner'
-      Test::Unit::Util::BacktraceFilter.module_eval { include Rails::BacktraceFilterForTestUnit }
-    end
+    else
+      # TODO: Figure out how to get the Rails::BacktraceFilter into minitest/unit
+      if defined?(Rails)
+        require 'rails/backtrace_cleaner'
+        Test::Unit::Util::BacktraceFilter.module_eval { include Rails::BacktraceFilterForTestUnit }
+      end
 
-    class TestCase &lt; ::Test::Unit::TestCase
       Assertion = Test::Unit::AssertionFailedError
+
+      require 'active_support/testing/default'
       include ActiveSupport::Testing::Default
-    end    
-  end
+    end
 
-  class TestCase
     include ActiveSupport::Testing::SetupAndTeardown
     include ActiveSupport::Testing::Assertions
     extend ActiveSupport::Testing::Declarative
   end
-end
\ No newline at end of file
+end</diff>
      <filename>activesupport/lib/active_support/test_case.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,30 +3,15 @@ require 'active_support/callbacks'
 module ActiveSupport
   module Testing
     module SetupAndTeardown
-      # For compatibility with Ruby &lt; 1.8.6
-      PASSTHROUGH_EXCEPTIONS =
-        if defined?(Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS)
-          Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
-        else
-          [NoMemoryError, SignalException, Interrupt, SystemExit]
-        end
-
       def self.included(base)
         base.class_eval do
           include ActiveSupport::Callbacks
           define_callbacks :setup, :teardown
 
-          if defined?(::MiniTest)
+          if defined? MiniTest
             include ForMiniTest
           else
-            begin
-              require 'mocha'
-              undef_method :run
-              alias_method :run, :run_with_callbacks_and_mocha
-            rescue LoadError
-              undef_method :run
-              alias_method :run, :run_with_callbacks_and_testunit
-            end
+            include ForClassicTestUnit
           end
         end
       end
@@ -50,74 +35,51 @@ module ActiveSupport
         end
       end
 
-      # This redefinition is unfortunate but test/unit shows us no alternative.
-      def run_with_callbacks_and_testunit(result) #:nodoc:
-        return if @method_name.to_s == &quot;default_test&quot;
+      module ForClassicTestUnit
+        # For compatibility with Ruby &lt; 1.8.6
+        PASSTHROUGH_EXCEPTIONS = Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS rescue [NoMemoryError, SignalException, Interrupt, SystemExit]
 
-        yield(Test::Unit::TestCase::STARTED, name)
-        @_result = result
-        begin
-          run_callbacks :setup
-          setup
-          __send__(@method_name)
-        rescue Test::Unit::AssertionFailedError =&gt; e
-          add_failure(e.message, e.backtrace)
-        rescue *PASSTHROUGH_EXCEPTIONS
-          raise
-        rescue Exception
-          add_error($!)
-        ensure
-          begin
-            teardown
-            run_callbacks :teardown, :enumerator =&gt; :reverse_each
-          rescue Test::Unit::AssertionFailedError =&gt; e
-            add_failure(e.message, e.backtrace)
-          rescue *PASSTHROUGH_EXCEPTIONS
-            raise
-          rescue Exception
-            add_error($!)
-          end
-        end
-        result.add_run
-        yield(Test::Unit::TestCase::FINISHED, name)
-      end
+        # This redefinition is unfortunate but test/unit shows us no alternative.
+        # Doubly unfortunate: hax to support Mocha's hax.
+        def run(result)
+          return if @method_name.to_s == &quot;default_test&quot;
 
-      # Doubly unfortunate: mocha does the same so we have to hax their hax.
-      def run_with_callbacks_and_mocha(result)
-        return if @method_name.to_s == &quot;default_test&quot;
+          if using_mocha = respond_to?(:mocha_verify)
+            assertion_counter = Mocha::TestCaseAdapter::AssertionCounter.new(result)
+          end
 
-        assertion_counter = Mocha::TestCaseAdapter::AssertionCounter.new(result)
-        yield(Test::Unit::TestCase::STARTED, name)
-        @_result = result
-        begin
+          yield(Test::Unit::TestCase::STARTED, name)
+          @_result = result
           begin
-            run_callbacks :setup
-            setup
-            __send__(@method_name)
-            mocha_verify(assertion_counter)
-          rescue Mocha::ExpectationError =&gt; e
-            add_failure(e.message, e.backtrace)
-          rescue Test::Unit::AssertionFailedError =&gt; e
-            add_failure(e.message, e.backtrace)
-          rescue Exception
-            raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class
-            add_error($!)
-          ensure
             begin
-              teardown
-              run_callbacks :teardown, :enumerator =&gt; :reverse_each
+              run_callbacks :setup
+              setup
+              __send__(@method_name)
+              mocha_verify(assertion_counter) if using_mocha
+            rescue Mocha::ExpectationError =&gt; e
+              add_failure(e.message, e.backtrace)
             rescue Test::Unit::AssertionFailedError =&gt; e
               add_failure(e.message, e.backtrace)
-            rescue Exception
-              raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class
-              add_error($!)
+            rescue Exception =&gt; e
+              raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
+              add_error(e)
+            ensure
+              begin
+                teardown
+                run_callbacks :teardown, :enumerator =&gt; :reverse_each
+              rescue Test::Unit::AssertionFailedError =&gt; e
+                add_failure(e.message, e.backtrace)
+              rescue Exception =&gt; e
+                raise if PASSTHROUGH_EXCEPTIONS.include?(e.class)
+                add_error(e)
+              end
             end
+          ensure
+            mocha_teardown if using_mocha
           end
-        ensure
-          mocha_teardown
+          result.add_run
+          yield(Test::Unit::TestCase::FINISHED, name)
         end
-        result.add_run
-        yield(Test::Unit::TestCase::FINISHED, name)
       end
     end
   end</diff>
      <filename>activesupport/lib/active_support/testing/setup_and_teardown.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c79fb32e93c7ed9d5c0f39194ee48183faf3b5c9</id>
    </parent>
  </parents>
  <author>
    <name>Jeremy Kemper</name>
    <login>jeremy</login>
    <email>jeremy@bitsweat.net</email>
  </author>
  <url>http://github.com/rails/rails/commit/e7208d382a3d8bae9ab13d8a380b1a2a05fd99b0</url>
  <id>e7208d382a3d8bae9ab13d8a380b1a2a05fd99b0</id>
  <committed-date>2008-11-22T19:22:45-08:00</committed-date>
  <authored-date>2008-11-22T19:18:30-08:00</authored-date>
  <message>Get ActiveSupport::TestCase working with classic Test::Unit and MiniTest. Fix broken Mocha + MiniTest. Assume ruby-core applies patch #771 fixing libraries which extend Test::Unit.</message>
  <tree>ea69c208bfce8f360189ffd95eedf9f550e65810</tree>
  <committer>
    <name>Jeremy Kemper</name>
    <login>jeremy</login>
    <email>jeremy@bitsweat.net</email>
  </committer>
</commit>
