aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/testing/isolation.rb
blob: 8b2957fbe1a84979a8977d601c833eda30e8ed7e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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