Sha256: 006c514ed0e8036b4ec6547bda9009e3493681b79865e0338af438767b57641d
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
require 'spec_helper' module Foreground describe Daemon do before do Process.stub(:kill) @cmd = ['some_daemon', '--with', 'arguments'] @pid_file = 'some_daemon.pid' @pid = 42 @args = [@cmd, @pid_file] @daemon = Daemon.new(@cmd, @pid_file) @daemon.stub(:watch) # ...or we'll wait forever. @daemon.stub(:system) # ...so that we don't run any stupid commands in our tests. end describe '.run' do it 'should run and register a new instance' do daemon = mock('daemon') daemon.should_receive(:run) Daemon.should_receive(:new).with(*@args).and_return(daemon) Daemon.daemon.should be_nil Daemon.run(*@args) Daemon.daemon.should be(daemon) end end describe '.kill' do it 'should forward signals to the daemon' do Daemon.daemon = mock('daemon') Daemon.daemon.should_receive(:kill).with(:FOO) Daemon.kill(:FOO) end end describe '#run' do it 'should run and watch the daemon' do @daemon.should_receive(:system).with(*@cmd).ordered @daemon.should_receive(:watch).ordered @daemon.run end end describe '#kill' do it 'should send the daemon a SIGTERM' do @daemon.stub(:pid).and_return(42) Process.should_receive(:kill).with(:TERM, 42) @daemon.kill end end describe '#pid' do it 'should return the daemons PID by PID file' do File.should_receive(:read).with(@pid_file).and_return("#{@pid}\n") @daemon.pid.should eql(@pid) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
foreground-0.0.4 | spec/foreground/daemon_spec.rb |
foreground-0.0.3 | spec/foreground/daemon_spec.rb |