fix process#alive? to not raise on no such file
[god.git] / test / test_conditions_process_running.rb
blob8bede9b866c09c3e6b88b9589b2d47c200fb917f
1 require File.dirname(__FILE__) + '/helper'
3 class TestConditionsProcessRunning < Test::Unit::TestCase
4   def test_missing_pid_file_returns_opposite
5     [true, false].each do |r|
6       c = Conditions::ProcessRunning.new
7       c.running = r
8     
9       c.stubs(:watch).returns(stub(:pid_file => ''))
10     
11       assert_equal !r, c.test
12     end
13   end
14   
15   def test_not_running_returns_opposite
16     [true, false].each do |r|
17       c = Conditions::ProcessRunning.new
18       c.running = r
19     
20       File.stubs(:exist?).returns(true)
21       c.stubs(:watch).returns(stub(:pid_file => ''))
22       File.stubs(:read).returns('5')
23       System::Process.any_instance.stubs(:exists?).returns(false)
24     
25       assert_equal !r, c.test
26     end
27   end
28   
29   def test_running_returns_same
30     [true, false].each do |r|
31       c = Conditions::ProcessRunning.new
32       c.running = r
33     
34       File.stubs(:exist?).returns(true)
35       c.stubs(:watch).returns(stub(:pid_file => ''))
36       File.stubs(:read).returns('5')
37       System::Process.any_instance.stubs(:exists?).returns(true)
38     
39       assert_equal r, c.test
40     end
41   end
42 end