1 require File.dirname(__FILE__) + '/helper'
6 raise "You forgot to stub fork"
10 raise "You forgot to stub exec"
15 class TestProcess < Test::Unit::TestCase
17 @p = God::Process.new(:name => 'foo', :pid_file => 'blah.pid')
18 @p.stubs(:test).returns true # so we don't try to mkdir_p
19 Process.stubs(:detach) # because we stub fork
22 # These actually excercise call_action in the back at this point - Kev
23 def test_call_action_with_string_should_fork_exec
24 @p.start = "do something"
25 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
27 Process.expects(:waitpid)
28 @p.call_action(:start)
31 def test_call_action_with_lambda_should_call
32 cmd = lambda { puts "Hi" }
35 @p.call_action(:start)
38 def test_default_pid_file
39 assert_equal File.join(God.pid_file_directory, 'foo.pid'), @p.default_pid_file
42 def test_call_action_without_pid_should_write_pid
43 # Only for start, restart
44 [:start, :restart].each do |action|
45 @p = God::Process.new(:name => 'foo')
46 @p.stubs(:test).returns true
47 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
49 Process.expects(:waitpid)
50 File.expects(:open).with(@p.default_pid_file, 'w')
51 @p.send("#{action}=", "run")
52 @p.call_action(action)
56 def test_call_action_should_not_write_pid_for_stop
58 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
60 Process.expects(:waitpid)
61 File.expects(:open).times(0)
66 def test_call_action_should_mkdir_p_if_pid_file_dir_existence_test_fails
68 IO.expects(:pipe).returns([StringIO.new('1234'), StringIO.new])
70 Process.expects(:waitpid)
71 @p.expects(:test).returns(false, true)
72 FileUtils.expects(:mkdir_p).with(God.pid_file_directory)
75 @p.call_action(:start)
78 def test_start_stop_restart_bang
79 [:start, :stop, :restart].each do |x|
80 @p.expects(:call_action).with(x)