PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 1module 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
12      pid = Process.fork do
13        exception = nil
14        begin
15          yield
16        rescue Exception => e
17          exception = e
18        end
19
20        writeme.write Marshal.dump(exception)
21
22        readme.close
23        writeme.close
24        exit! # prevent at_exit hooks from running (e.g. minitest)
25      end
26
27      writeme.close
28      Process.waitpid(pid)
29
30      exception = Marshal.load(readme.read)
31      readme.close
32
33      raise exception if exception
34    end
35  end
36end
37