Sha256: a5121225c0cac8a5cd19ca987c031104e5650afd3f0ea1d3e69b603add6d9003

Contents?: true

Size: 555 Bytes

Versions: 16

Compression:

Stored size: 555 Bytes

Contents

module InSubProcess
  # Useful as a way to isolate a global change to a subprocess.
  def in_sub_process
    readme, writeme = IO.pipe

    pid = Process.fork do
      value = nil
      begin
        yield
      rescue => e
        value = e
      end

      writeme.write Marshal.dump(value)

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

    writeme.close
    Process.waitpid(pid)

    if exception = Marshal.load(readme.read)
      raise exception
    end

    readme.close
  end
end

Version data entries

16 entries across 16 versions & 6 rubygems

Version Path
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/support/in_sub_process.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/support/in_sub_process.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/spec/support/in_sub_process.rb
remq-0.0.4 vendor/bundle/gems/rspec-expectations-2.12.1/spec/support/in_sub_process.rb
remq-0.0.3 vendor/bundle/gems/rspec-expectations-2.12.1/spec/support/in_sub_process.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/spec/support/in_sub_process.rb
rspec-expectations-2.12.1 spec/support/in_sub_process.rb
rspec-expectations-2.12.0 spec/support/in_sub_process.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/support/in_sub_process.rb
gem_repackager-0.1.0 support/gems/rspec-expectations-2.11.2/spec/support/in_sub_process.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/spec/support/in_sub_process.rb
rspec-expectations-2.11.3 spec/support/in_sub_process.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/spec/support/in_sub_process.rb
rspec-expectations-2.11.2 spec/support/in_sub_process.rb
rspec-expectations-2.11.1 spec/support/in_sub_process.rb
rspec-expectations-2.11.0 spec/support/in_sub_process.rb