aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/isolation.rb
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/active_support/testing/isolation.rb
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/active_support/testing/isolation.rb')
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb39
1 files changed, 39 insertions, 0 deletions
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