module RSpec::Support::InSubProcess

Public Instance Methods

in_sub_process(prevent_warnings=true) { || ... } click to toggle source

rubocop:disable MethodLength

# File lib/rspec/support/spec/in_sub_process.rb, line 9
def in_sub_process(prevent_warnings=true)
  readme, writeme = IO.pipe

  pid = Process.fork do
    exception = nil
    warning_preventer = $stderr = RSpec::Support::StdErrSplitter.new($stderr)

    begin
      yield
      warning_preventer.verify_no_warnings! if prevent_warnings
    rescue Support::AllExceptionsExceptOnesWeMustNotRescue => e
      exception = e
    end

    writeme.write Marshal.dump(exception)

    readme.close
    writeme.close
    exit! # prevent at_exit hooks from running (e.g. minitest)
  end

  writeme.close
  Process.waitpid(pid)

  exception = Marshal.load(readme.read)
  readme.close

  raise exception if exception
end
Also aliased as: in_sub_process_if_possible
in_sub_process_if_possible(prevent_warnings=true)

rubocop:enable MethodLength

Alias for: in_sub_process