Sha256: 0de87c027508e248d7a43ef1d18ac2ceb683b6d0a495b32cb5a80b8299020e3b

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

require 'phantom'

describe Phantom do
  pid_file = 'tmp/phantom.pid'

  after do
    File.delete pid_file if File.exist? pid_file
  end

  it 'should remove the pid file when normally ends.' do
    Phantom.run(pid_file: pid_file) {}
    File.should_not exist(pid_file)
  end

  it 'should raise error if pre-exists pid file' do
    File.new(pid_file, 'w').close
    expect{
      Phantom.run(pid_file: pid_file) do end
    }.to raise_error(Phantom::ForkError)
  end

  it 'should call on_ok when sub processed normally ends' do
    i = 0
    err = nil
    Phantom.run(pid_file: pid_file, on_ok: lambda{i += 1}, on_error: lambda{|e| err = e}) do
    end
    sleep 3
    i.should == 1
    err.should == nil
  end

  it 'should call on_error when sub process raises an unhandled error' do
    err = nil
    i = 0
    Phantom.run(pid_file: pid_file, on_ok: lambda{i += 1}, on_error: lambda{|e| err = e}) do
      raise 'Wa ha ha!'
      i += 1
    end

    sleep 3

    err.should be_an(StandardError)
    err.message.should == 'Wa ha ha!'
    i.should == 0
  end

  it 'should be OK if pid_file is not given' do
    Phantom.run do end
  end

  it 'should return a Phantom::Base instance when run' do
    phantom = Phantom.run do end
    phantom.should be_an(Phantom::Base)
  end

  it 'should do nothing if block is not given' do
    phantom = Phantom.run
    phantom.pid.should be_nil
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
phantom-0.0.3.pre spec/phantom_spec.rb
phantom-0.0.2.pre spec/phantom_spec.rb
phantom-0.0.1 spec/phantom_spec.rb