Sha256: 54f31f9b6a97011d629afa09e57ab2183066eaa3a245942b94c39648da3a9dea

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

require File.expand_path('../spec_helper', __FILE__)

describe ChildProcess do

  EXIT_TIMEOUT = 10

  it "returns self when started" do
    process = sleeping_ruby

    process.start.should == process
    process.should be_started
  end

  it "knows if the process crashed" do
    process = exit_with(1).start

    within(EXIT_TIMEOUT) {
      process.should be_crashed
    }
  end

  it "knows if the process didn't crash" do
    process = exit_with(0).start
    process.poll_for_exit(EXIT_TIMEOUT)

    process.should_not be_crashed
  end

  it "escalates if TERM is ignored" do
    process = ignored('TERM').start
    process.stop
    process.should be_exited
  end

  it "accepts a timeout argument to #stop" do
    process = sleeping_ruby.start
    process.stop(EXIT_TIMEOUT)
  end

  it "lets child process inherit the environment of the current process" do
    Tempfile.open("env-spec") do |file|
      with_env('env-spec' => 'yes') do
        process = write_env(file.path).start
        process.poll_for_exit(EXIT_TIMEOUT)
      end

      file.rewind
      child_env = eval(file.read)
      child_env['env-spec'].should == 'yes'
    end
  end

  it "passes arguments to the child" do
    args = ["foo", "bar"]

    Tempfile.open("argv-spec") do |file|
      process = write_argv(file.path, *args).start
      process.poll_for_exit(EXIT_TIMEOUT)

      file.rewind
      file.read.should == args.inspect
    end
  end

  it "lets a detached child live on" do
    # hmm. how do we spec this?
  end

  it_should_behave_like "unix process" if ChildProcess.platform == :unix
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
childprocess-0.1.0 spec/childprocess_spec.rb
childprocess-0.0.9 spec/childprocess_spec.rb