summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-09-25 19:04:28 -0700
committerJohn Keiser <john@johnkeiser.com>2015-09-28 17:34:55 -0700
commit68656820438b84d433ae9015b953790f67ddf0ec (patch)
tree1b493a5c2beb9ed8fdacc67668608cb9e5fd7716 /spec/support
parentfd01105a5214cf90eea59c09d4fce14f0abb586e (diff)
downloadchef-68656820438b84d433ae9015b953790f67ddf0ec.tar.gz
Add system providers to the list of world-stubbed stuff
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/shared/unit/double_world.rb35
1 files changed, 27 insertions, 8 deletions
diff --git a/spec/support/shared/unit/double_world.rb b/spec/support/shared/unit/double_world.rb
index 3b528f06e2..1fdd8fcccb 100644
--- a/spec/support/shared/unit/double_world.rb
+++ b/spec/support/shared/unit/double_world.rb
@@ -27,23 +27,23 @@
shared_context "double world" do
let(:world) { DoubleWorld.new }
before do
- allow(::File).to receive(:exists?) { |f| world.files.has_key?(f) }
+ allow(::File).to receive(:exist?) { |f| world.files.has_key?(f) }
+ allow(::File).to receive(:exists?) { |f| world.files.has_key?(f) }
allow(::File).to receive(:executable?) { |f| world.files.has_key?(f) }
- allow(::File).to receive(:open) { |f| StringIO.new(world.files[f]) }
+ allow(::File).to receive(:open) { |f| StringIO.new(world.files[f]) }
- allow(::Chef::Mixin::ShellOut).to receive(:shell_out!) do |c|
- raise "hi"
+ allow(::Mixlib::ShellOut).to receive(:new) do |c|
result = world.commands[c]
case result
when String
- Mash.new(stdout: result)
+ result = { stdout: result }
when Integer
- Mash.new(exitstatus: result)
+ result = { exitstatus: result }
when Hash
- Mash.new(result)
else
- raise ArgumentError, result
+ raise ArgumentError, "Result for command #{c} unexpected or undefined: #{result.inspect}"
end
+ DoubleShellout.new(result)
end
end
@@ -57,4 +57,23 @@ shared_context "double world" do
attr_reader :files
attr_reader :commands
end
+
+ class DoubleShellout
+ def initialize(properties)
+ @properties = {
+ stdout: "",
+ stderr: "",
+ exitstatus: 0
+ }.merge(properties)
+ end
+ def method_missing(name, *args)
+ @properties[name.to_sym]
+ end
+ def error?
+ exitstatus != 0
+ end
+ def error!
+ raise Mixlib::ShellOut::ShellCommandFailed, "Expected process to exit with 0, but received #{exitstatus}" if error?
+ end
+ end
end