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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/active_support/testing/isolation.rb', line 36

def run_in_isolation(&blk)
  IO.pipe do |read, write|
    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
        test_result = defined?(Minitest::Result) ? Minitest::Result.from(self) : dup
        result = Marshal.dump(test_result)
      end

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

    write.close
    result = read.read
    _, status = Process.wait2(pid)
    return status, result.unpack1("m")
  end
end