summaryrefslogtreecommitdiff
path: root/spec/unit/mixin/powershell_out_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/mixin/powershell_out_spec.rb')
-rw-r--r--spec/unit/mixin/powershell_out_spec.rb45
1 files changed, 32 insertions, 13 deletions
diff --git a/spec/unit/mixin/powershell_out_spec.rb b/spec/unit/mixin/powershell_out_spec.rb
index 9524557c4c..8e5f3588ce 100644
--- a/spec/unit/mixin/powershell_out_spec.rb
+++ b/spec/unit/mixin/powershell_out_spec.rb
@@ -18,7 +18,7 @@
require "spec_helper"
require "chef/mixin/powershell_out"
-describe Chef::Mixin::PowershellOut, :windows_only do
+describe Chef::Mixin::PowershellOut do
let(:shell_out_class) { Class.new { include Chef::Mixin::PowershellOut } }
subject(:object) { shell_out_class.new }
let(:architecture) { "something" }
@@ -28,24 +28,43 @@ describe Chef::Mixin::PowershellOut, :windows_only do
describe "#powershell_out" do
it "runs a command and returns the shell_out object" do
- result = object.powershell_out("Get-Process")
- expect(result.stderr).to be == ""
+ ret = double("Mixlib::ShellOut")
+ expect(object).to receive(:shell_out).with(
+ "powershell.exe #{flags} -Command \"Get-Process\"",
+ {}
+ ).and_return(ret)
+ expect(object.powershell_out("Get-Process")).to eql(ret)
end
it "passes options" do
- result = object.powershell_out("Get-Process", timeout: 600)
- expect(result.stderr).to be == ""
+ ret = double("Mixlib::ShellOut")
+ expect(object).to receive(:shell_out).with(
+ "powershell.exe #{flags} -Command \"Get-Process\"",
+ timeout: 600
+ ).and_return(ret)
+ expect(object.powershell_out("Get-Process", timeout: 600)).to eql(ret)
end
+ end
- context "when double quote is passed in the powershell command" do
- it "passes if double quote is appended with single escape" do
- result = object.powershell_out("Write-Verbose \"Some String\" -Verbose")
- expect(result.stderr).to be == ""
- end
+ describe "#powershell_out!" do
+ it "runs a command and returns the shell_out object" do
+ mixlib_shellout = double("Mixlib::ShellOut")
+ expect(object).to receive(:shell_out).with(
+ "powershell.exe #{flags} -Command \"Get-Process\"",
+ {}
+ ).and_return(mixlib_shellout)
+ expect(mixlib_shellout).to receive(:error!)
+ expect(object.powershell_out!("Get-Process")).to eql(mixlib_shellout)
+ end
- it "raises error if double quote is passed with double escape characters" do
- expect { object.powershell_out("Write-Verbose \\\"Some String\\\" -Verbose") }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
- end
+ it "passes options" do
+ mixlib_shellout = double("Mixlib::ShellOut")
+ expect(object).to receive(:shell_out).with(
+ "powershell.exe #{flags} -Command \"Get-Process\"",
+ timeout: 600
+ ).and_return(mixlib_shellout)
+ expect(mixlib_shellout).to receive(:error!)
+ expect(object.powershell_out!("Get-Process", timeout: 600)).to eql(mixlib_shellout)
end
end
end