aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/isolation.rb
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2009-12-30 20:48:15 -0800
committerCarl Lerche <carllerche@mac.com>2009-12-30 20:48:46 -0800
commitd39d7f5f444db724ddfb2dc5c15177e519b349f0 (patch)
tree70bfb82db39785adf5970e855e77494206d45df7 /activesupport/lib/active_support/testing/isolation.rb
parent1fbd02e44618f1f56e1d9d0af85c6a4108a66532 (diff)
downloadrails-d39d7f5f444db724ddfb2dc5c15177e519b349f0.tar.gz
rails-d39d7f5f444db724ddfb2dc5c15177e519b349f0.tar.bz2
rails-d39d7f5f444db724ddfb2dc5c15177e519b349f0.zip
Allow ActiveSupport's isolation tests to run with MiniTest on 1.9
Diffstat (limited to 'activesupport/lib/active_support/testing/isolation.rb')
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb64
1 files changed, 46 insertions, 18 deletions
diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb
index 81f7e3c9df..453f4fcc0f 100644
--- a/activesupport/lib/active_support/testing/isolation.rb
+++ b/activesupport/lib/active_support/testing/isolation.rb
@@ -36,28 +36,56 @@ module ActiveSupport
!ENV["NO_FORK"] && RUBY_PLATFORM !~ /mswin|mingw|java/
end
- def run(result)
- unless defined?(@@ran_class_setup)
- self.class.setup if self.class.respond_to?(:setup)
- @@ran_class_setup = true
+ def self.included(base)
+ if defined?(::MiniTest) && base < ::MiniTest::Unit::TestCase
+ base.send :include, MiniTest
+ elsif defined?(Test::Unit)
+ base.send :include, TestUnit
end
+ end
+
+ module TestUnit
+ def run(result)
+ unless defined?(@@ran_class_setup)
+ self.class.setup if self.class.respond_to?(:setup)
+ @@ran_class_setup = true
+ end
- yield(Test::Unit::TestCase::STARTED, name)
+ yield(Test::Unit::TestCase::STARTED, name)
- @_result = result
+ @_result = result
- serialized = run_in_isolation do |proxy|
- begin
- super(proxy) { }
- rescue Exception => e
- proxy.add_error(Test::Unit::Error.new(name, e))
+ serialized = run_in_isolation do |proxy|
+ begin
+ super(proxy) { }
+ rescue Exception => e
+ proxy.add_error(Test::Unit::Error.new(name, e))
+ end
end
+
+ retval, proxy = Marshal.load(serialized)
+ proxy.__replay__(@_result)
+
+ yield(Test::Unit::TestCase::FINISHED, name)
+ retval
end
+ end
- proxy = Marshal.load(serialized)
- proxy.__replay__(@_result)
+ module MiniTest
+ def run(runner)
+ unless defined?(@@ran_class_setup)
+ self.class.setup if self.class.respond_to?(:setup)
+ @@ran_class_setup = true
+ end
- yield(Test::Unit::TestCase::FINISHED, name)
+ serialized = run_in_isolation do |runner|
+ super(runner)
+ end
+
+ retval, proxy = Marshal.load(serialized)
+ proxy.__replay__(runner)
+ retval
+ end
end
module Forking
@@ -67,8 +95,8 @@ module ActiveSupport
pid = fork do
read.close
proxy = ProxyTestResult.new
- yield proxy
- write.puts [Marshal.dump(proxy)].pack("m")
+ retval = yield proxy
+ write.puts [Marshal.dump([retval, proxy])].pack("m")
exit!
end
@@ -87,9 +115,9 @@ module ActiveSupport
if ENV["ISOLATION_TEST"]
proxy = ProxyTestResult.new
- yield proxy
+ retval = yield proxy
File.open(ENV["ISOLATION_OUTPUT"], "w") do |file|
- file.puts [Marshal.dump(proxy)].pack("m")
+ file.puts [Marshal.dump([retval, proxy])].pack("m")
end
exit!
else