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



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/active_support/testing/isolation.rb', line 94

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

  pid = fork do
    read.close
    proxy = ProxyTestResult.new
    retval = yield proxy
    write.puts [Marshal.dump([retval, proxy])].pack("m")
    exit!
  end

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