diff options
author | Luke Kanies <luke@madstop.com> | 2007-11-20 01:19:34 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-11-20 01:19:34 -0600 |
commit | 7fe5bfcd28fe61422ffa2071bfc36f753f83c11a (patch) | |
tree | 79c1a8d49308a6c29e2cbb2082f3314a586a6bc8 | |
parent | 8cc07adda20b4e63bbad5b2759303d00d215341c (diff) | |
download | puppet-7fe5bfcd28fe61422ffa2071bfc36f753f83c11a.tar.gz puppet-7fe5bfcd28fe61422ffa2071bfc36f753f83c11a.tar.xz puppet-7fe5bfcd28fe61422ffa2071bfc36f753f83c11a.zip |
Fixing the exec spec so it works when non-root and is a bit cleaner
-rwxr-xr-x | spec/unit/ral/exec.rb | 54 |
1 files changed, 12 insertions, 42 deletions
diff --git a/spec/unit/ral/exec.rb b/spec/unit/ral/exec.rb index 8edf6535d..cf0e02929 100755 --- a/spec/unit/ral/exec.rb +++ b/spec/unit/ral/exec.rb @@ -8,7 +8,8 @@ module ExecModuleTesting def create_resource(command, output, exitstatus) @user_name = 'some_user_name' @group_name = 'some_group_name' - @execer = Puppet::Type.type(:exec).create(:name => command, :user => @user_name, :group => @group_name) + Puppet.features.stubs(:root?).returns(true) + @execer = Puppet::Type.type(:exec).create(:name => command, :path => %w{/usr/bin /bin}, :user => @user_name, :group => @group_name) status = stub "process" status.stubs(:exitstatus).returns(exitstatus) @@ -33,31 +34,22 @@ describe Puppet::Type::Exec, " when execing" do include ExecModuleTesting it "should use the 'run_and_capture' method to exec" do - command = "/bin/true" + command = "true" create_resource(command, "", 0) @execer.refresh.should == :executed_command end it "should report a failure" do - command = "/bin/false" + command = "false" create_resource(command, "", 1) - # no idea, why should raise_error doesn't work here - raised = false - begin - @execer.refresh.should raise_error(Puppet::Error) - rescue Puppet::Error - raised = true - end - unless raised - raise "didn't receive Puppet::Error" - end + proc { @execer.refresh }.should raise_error(Puppet::Error) end it "should log the output on success" do #Puppet::Util::Log.newdestination :console - command = "/bin/false" + command = "false" output = "output1\noutput2\n" create_logging_resource(command, output, 0, true, :err) expect_output(output, :err) @@ -66,21 +58,12 @@ describe Puppet::Type::Exec, " when execing" do it "should log the output on failure" do #Puppet::Util::Log.newdestination :console - command = "/bin/false" + command = "false" output = "output1\noutput2\n" create_logging_resource(command, output, 1, true, :err) expect_output(output, :err) - # no idea, why should raise_error doesn't work here - raised = false - begin - @execer.refresh.should raise_error(Puppet::Error) - rescue Puppet::Error - raised = true - end - unless raised - raise "didn't receive Puppet::Error" - end + proc { @execer.refresh }.should raise_error(Puppet::Error) end end @@ -91,33 +74,20 @@ describe Puppet::Type::Exec, " when logoutput=>on_failure is set," do it "should log the output on failure" do #Puppet::Util::Log.newdestination :console - command = "/bin/false" + command = "false" output = "output1\noutput2\n" create_logging_resource(command, output, 1, :on_failure, :err) expect_output(output, :err) - # no idea, why should raise_error doesn't work here - raised = false - begin - @execer.refresh.should raise_error(Puppet::Error) - rescue Puppet::Error - raised = true - end - unless raised - raise "didn't receive Puppet::Error" - end + proc { @execer.refresh }.should raise_error(Puppet::Error) end it "shouldn't log the output on success" do #Puppet::Util::Log.newdestination :console - command = "/bin/true" + command = "true" output = "output1\noutput2\n" create_logging_resource(command, output, 0, :on_failure, :err) - @execer.property(:returns).stubs(:err) do - fail "logging, where non was expected" - end + @execer.property(:returns).expects(:err).never @execer.refresh end - end - |