/vendor/bundle/jruby/2.1/gems/rspec-core-2.14.8/spec/support/in_sub_process.rb

https://github.com/delowong/logstash · Ruby · 37 lines · 29 code · 7 blank · 1 comment · 3 complexity · 7998102307ba4b1a623eeb0eb1520cff MD5 · raw file

  1. module InSubProcess
  2. if RUBY_PLATFORM == 'java'
  3. def in_sub_process
  4. pending "This spec requires forking to work properly, " +
  5. "and JRuby does not support forking"
  6. end
  7. else
  8. # Useful as a way to isolate a global change to a subprocess.
  9. def in_sub_process
  10. readme, writeme = IO.pipe
  11. pid = Process.fork do
  12. exception = nil
  13. begin
  14. yield
  15. rescue Exception => e
  16. exception = e
  17. end
  18. writeme.write Marshal.dump(exception)
  19. readme.close
  20. writeme.close
  21. exit! # prevent at_exit hooks from running (e.g. minitest)
  22. end
  23. writeme.close
  24. Process.waitpid(pid)
  25. exception = Marshal.load(readme.read)
  26. readme.close
  27. raise exception if exception
  28. end
  29. end
  30. end