aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-30 12:00:50 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-06-30 12:00:50 -0700
commit575b95ea0bf3d3fff6f47dddad23c754fb294604 (patch)
tree142ef4a20814e41281b385b1684bf5d5f14de035 /activesupport/lib
parent9101941c1259627df99c5c13b8e893d5d593265c (diff)
downloadrails-575b95ea0bf3d3fff6f47dddad23c754fb294604.tar.gz
rails-575b95ea0bf3d3fff6f47dddad23c754fb294604.tar.bz2
rails-575b95ea0bf3d3fff6f47dddad23c754fb294604.zip
Created AS::Testing::Isolation which runs each test case in a separate process.
This allows for testing rails bootup (files are required, correct constants are set, etc...). Currently, this is implemented via forking only, but we will add support for jruby and windows shortly.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/test_case.rb1
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb39
2 files changed, 40 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb
index bab2a401eb..e99a4854ce 100644
--- a/activesupport/lib/active_support/test_case.rb
+++ b/activesupport/lib/active_support/test_case.rb
@@ -13,6 +13,7 @@ require 'active_support/testing/assertions'
require 'active_support/testing/deprecation'
require 'active_support/testing/declarative'
require 'active_support/testing/pending'
+require 'active_support/testing/isolation'
module ActiveSupport
class TestCase < ::Test::Unit::TestCase
diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb
new file mode 100644
index 0000000000..8b2957fbe1
--- /dev/null
+++ b/activesupport/lib/active_support/testing/isolation.rb
@@ -0,0 +1,39 @@
+module ActiveSupport::Testing
+ class ProxyTestResult
+ def initialize
+ @calls = []
+ end
+
+ def __replay__(result)
+ @calls.each do |name, args|
+ result.send(name, *args)
+ end
+ end
+
+ def method_missing(name, *args)
+ @calls << [name, args]
+ end
+ end
+
+ module Isolation
+ def run(result)
+ yield(Test::Unit::TestCase::STARTED, name)
+
+ read, write = IO.pipe
+
+ pid = fork do
+ # child
+ read.close
+ proxy = ProxyTestResult.new
+ super(proxy) { }
+ write.puts [Marshal.dump(proxy)].pack("m")
+ exit!
+ end
+
+ write.close
+ Marshal.load(read.read.unpack("m")[0]).__replay__(result)
+ Process.wait2(pid)
+ yield(Test::Unit::TestCase::FINISHED, name)
+ end
+ end
+end \ No newline at end of file