123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Defined in: activesupport/lib/active_support/testing/isolation.rb

Instance Method Summary

Instance Method Details

#run_in_isolation(&blk)

[ GitHub ]

  
# File 'activesupport/lib/active_support/testing/isolation.rb', line 27

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
      test_result = defined?(Minitest::Result) ? Minitest::Result.from(self) : dup
      result = Marshal.dump(test_result)
    end

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

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