summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2011-03-07 16:52:19 -0800
committerPaul Berry <paul@puppetlabs.com>2011-03-07 16:52:19 -0800
commit8dbdcb057115bb2abdca22230d819303ff18ed6d (patch)
tree39b3d4fc5ad5443de66e856d5eaf7f6d5ea09efb /spec/unit
parent609ddcf2b1ae0c835973a584ac20796d962334f6 (diff)
parent23d1c0346a609369b457da876714c6671fcf3d44 (diff)
downloadpuppet-8dbdcb057115bb2abdca22230d819303ff18ed6d.tar.gz
puppet-8dbdcb057115bb2abdca22230d819303ff18ed6d.tar.xz
puppet-8dbdcb057115bb2abdca22230d819303ff18ed6d.zip
Merge branch 'maint/2.6.next/make_execute_stubbable' into 2.6.next
* maint/2.6.next/make_execute_stubbable: Maint: Added the ability to replace the behavior of Puppet::Util.execute with an arbitrary code block for ease in spec testing.
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/util/execution_stub_spec.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/unit/util/execution_stub_spec.rb b/spec/unit/util/execution_stub_spec.rb
new file mode 100644
index 000000000..14cf9c67a
--- /dev/null
+++ b/spec/unit/util/execution_stub_spec.rb
@@ -0,0 +1,35 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Puppet::Util::ExecutionStub do
+ it "should use the provided stub code when 'set' is called" do
+ Puppet::Util::ExecutionStub.set do |command, options|
+ command.should == ['/bin/foo', 'bar']
+ "stub output"
+ end
+ Puppet::Util::ExecutionStub.current_value.should_not == nil
+ Puppet::Util.execute(['/bin/foo', 'bar']).should == "stub output"
+ end
+
+ it "should automatically restore normal execution at the conclusion of each spec test" do
+ # Note: this test relies on the previous test creating a stub.
+ Puppet::Util::ExecutionStub.current_value.should == nil
+ end
+
+ it "should restore normal execution after 'reset' is called" do
+ true_command = Puppet::Util.which('true') # Note: "true" exists at different paths in different OSes
+ stub_call_count = 0
+ Puppet::Util::ExecutionStub.set do |command, options|
+ command.should == [true_command]
+ stub_call_count += 1
+ 'stub called'
+ end
+ Puppet::Util.execute([true_command]).should == 'stub called'
+ stub_call_count.should == 1
+ Puppet::Util::ExecutionStub.reset
+ Puppet::Util::ExecutionStub.current_value.should == nil
+ Puppet::Util.execute([true_command]).should == ''
+ stub_call_count.should == 1
+ end
+end