summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util
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 /lib/puppet/util
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 'lib/puppet/util')
-rw-r--r--lib/puppet/util/execution_stub.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/puppet/util/execution_stub.rb b/lib/puppet/util/execution_stub.rb
new file mode 100644
index 000000000..af74e0f72
--- /dev/null
+++ b/lib/puppet/util/execution_stub.rb
@@ -0,0 +1,26 @@
+module Puppet::Util
+ class ExecutionStub
+ class << self
+ # Set a stub block that Puppet::Util.execute() should invoke instead
+ # of actually executing commands on the target machine. Intended
+ # for spec testing.
+ #
+ # The arguments passed to the block are |command, options|, where
+ # command is an array of strings and options is an options hash.
+ def set(&block)
+ @value = block
+ end
+
+ # Uninstall any execution stub, so that calls to
+ # Puppet::Util.execute() behave normally again.
+ def reset
+ @value = nil
+ end
+
+ # Retrieve the current execution stub, or nil if there is no stub.
+ def current_value
+ @value
+ end
+ end
+ end
+end