Module: ActiveSupport::Testing::Isolation::Forking

Defined in:
lib/active_support/testing/isolation.rb

Instance Method Summary collapse

Instance Method Details

#run_in_isolation(&blk) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_support/testing/isolation.rb', line 25

def run_in_isolation(&blk)
  read, write = IO.pipe
  read.binmode
  write.binmode

  pid = fork do
    read.close
    yield
    begin
      if error?
        failures.map! { |e|
          begin
            Marshal.dump e
            e
          rescue TypeError
            ex = Exception.new e.message
            ex.set_backtrace e.backtrace
            Minitest::UnexpectedError.new ex
          end
        }
      end
      result = Marshal.dump(dup)
    end

    write.puts [result].pack("m")
    exit!
  end

  write.close
  result = read.read
  Process.wait2(pid)
  return result.unpack("m")[0]
end