prevent carry-over conditions
[god.git] / test / test_conditions_process_running.rb
blobc0b709d78cf61e74d8408314f6579366391aabf4
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 => 123, :name => 'foo'))
10     
11       # no_stdout do
12         assert_equal !r, c.test
13       # end
14     end
15   end
16   
17   def test_not_running_returns_opposite
18     [true, false].each do |r|
19       c = Conditions::ProcessRunning.new
20       c.running = r
21     
22       File.stubs(:exist?).returns(true)
23       c.stubs(:watch).returns(stub(:pid => 123))
24       File.stubs(:read).returns('5')
25       System::Process.any_instance.stubs(:exists?).returns(false)
26     
27       assert_equal !r, c.test
28     end
29   end
30   
31   def test_running_returns_same
32     [true, false].each do |r|
33       c = Conditions::ProcessRunning.new
34       c.running = r
35     
36       File.stubs(:exist?).returns(true)
37       c.stubs(:watch).returns(stub(:pid => 123))
38       File.stubs(:read).returns('5')
39       System::Process.any_instance.stubs(:exists?).returns(true)
40     
41       assert_equal r, c.test
42     end
43   end
44 end