57bb9a3dc754bf3912191ce256b634c966ab72f8
[packages/precise/mcollective.git] / spec / unit / unix_daemon_spec.rb
1 #!/usr/bin/env rspec
2
3 require 'spec_helper'
4 require 'mcollective/unix_daemon'
5
6 module MCollective
7   describe UnixDaemon do
8     describe "#daemonize_runner" do
9       it "should not run on the windows platform" do
10         Util.expects("windows?").returns(true)
11         expect { UnixDaemon.daemonize_runner }.to raise_error("The Unix Daemonizer can not be used on the Windows Platform")
12       end
13
14       it "should write the pid file if requested" do
15         f = mock
16         f.expects(:write).with(Process.pid)
17
18         File.expects(:open).with("/nonexisting", "w").yields(f)
19
20         r = mock
21         r.expects(:run)
22
23         Runner.expects(:new).returns(r)
24         UnixDaemon.expects(:daemonize).yields
25
26         UnixDaemon.daemonize_runner("/nonexisting")
27       end
28
29       it "should not write a pid file unless requested" do
30         r = mock
31         r.expects(:run)
32
33         UnixDaemon.expects(:daemonize).yields
34         Runner.expects(:new).returns(r)
35         File.expects(:open).never
36
37         UnixDaemon.daemonize_runner(nil)
38       end
39     end
40   end
41 end