diff options
| author | Markus Roberts <Markus@reality.com> | 2010-06-28 17:10:20 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-06-28 17:10:20 -0700 |
| commit | fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2 (patch) | |
| tree | 6ed2204d72c6924e867a1320d3b7e6728035f1a1 /spec/unit/indirector/exec_spec.rb | |
| parent | 9a94ee274c39c261cd49e688a7bd7ea0eb73af50 (diff) | |
| download | puppet-fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2.tar.gz puppet-fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2.tar.xz puppet-fdc8c3509b5ac5bc170c54d72b2c2bafb58409f2.zip | |
[#3994-part 3] rename spec tests from *_spec_spec to *_spec.rb
Part 2 re-did the change on the spec files, which it shouldn't have.
Diffstat (limited to 'spec/unit/indirector/exec_spec.rb')
| -rwxr-xr-x | spec/unit/indirector/exec_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/unit/indirector/exec_spec.rb b/spec/unit/indirector/exec_spec.rb new file mode 100755 index 000000000..4a7e2b50e --- /dev/null +++ b/spec/unit/indirector/exec_spec.rb @@ -0,0 +1,56 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/indirector/exec' + +describe Puppet::Indirector::Exec do + before do + @indirection = stub 'indirection', :name => :testing + Puppet::Indirector::Indirection.expects(:instance).with(:testing).returns(@indirection) + @exec_class = Class.new(Puppet::Indirector::Exec) do + def self.to_s + "Testing::Mytype" + end + + attr_accessor :command + end + + @searcher = @exec_class.new + @searcher.command = ["/echo"] + + @request = stub 'request', :key => "foo" + end + + it "should throw an exception if the command is not an array" do + @searcher.command = "/usr/bin/echo" + proc { @searcher.find(@request) }.should raise_error(Puppet::DevError) + end + + it "should throw an exception if the command is not fully qualified" do + @searcher.command = ["mycommand"] + proc { @searcher.find(@request) }.should raise_error(ArgumentError) + end + + it "should execute the command with the object name as the only argument" do + @searcher.expects(:execute).with(%w{/echo foo}) + @searcher.find(@request) + end + + it "should return the output of the script" do + @searcher.expects(:execute).with(%w{/echo foo}).returns("whatever") + @searcher.find(@request).should == "whatever" + end + + it "should return nil when the command produces no output" do + @searcher.expects(:execute).with(%w{/echo foo}).returns(nil) + @searcher.find(@request).should be_nil + end + + it "should return nil and log an error if there's an execution failure" do + @searcher.expects(:execute).with(%w{/echo foo}).raises(Puppet::ExecutionFailure.new("message")) + + Puppet.expects(:err) + @searcher.find(@request).should be_nil + end +end |
