Module: Minitest::ForkExecutor::ClassMethods

Defined in:
lib/minitest/fork_executor.rb

Instance Method Summary collapse

Instance Method Details

#run_one_method(klass, method_name) ⇒ Object

The updated version of Minitest.run_one_method that forks before actually running a test case, makes the child run it and send the result to the parent process.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/minitest/fork_executor.rb', line 20

def run_one_method klass, method_name
  read_io, write_io = IO.pipe
  read_io.binmode
  write_io.binmode

  if fork
    # Parent: load the result sent from the child

    write_io.close
    result = Marshal.load(read_io)
    read_io.close

    Process.wait
  else
    # Child: just run normally, dump the result, and exit the process to
    # avoid double-reporting.
    result = super

    read_io.close
    Marshal.dump(result, write_io)
    write_io.close
    exit
  end

  result
end