summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-30 20:47:32 -0400
committerHo-Sheng Hsiao <hosh@opscode.com>2012-05-10 14:48:21 -0400
commit743dd889999b6a5c4e4e7dbc4dd3d37dd9d92820 (patch)
tree126ee8442e249a686aca71bd83f429c2c4af3f88 /spec
parent0f734cef401fd93cd8409e9c834d9300f8026ac0 (diff)
downloadmixlib-shellout-743dd889999b6a5c4e4e7dbc4dd3d37dd9d92820.tar.gz
[CHEF-2994][WINDOWS] Added unit tests for private method #command_to_run
Fixed bug with quoted .cmd files Fixed bug with finding .bat in the middle of the filename
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/shellout/windows_spec.rb113
1 files changed, 113 insertions, 0 deletions
diff --git a/spec/mixlib/shellout/windows_spec.rb b/spec/mixlib/shellout/windows_spec.rb
new file mode 100644
index 0000000..a5586f7
--- /dev/null
+++ b/spec/mixlib/shellout/windows_spec.rb
@@ -0,0 +1,113 @@
+require 'spec_helper'
+
+describe Mixlib::ShellOut::Windows, :windows_only => true do
+
+ # Caveat: Private API methods are subject to change without notice.
+ # Monkeypatch at your own risk.
+ context 'for private API methods' do
+ describe '#command_to_run' do
+ subject { stubbed_shell_out.send(:command_to_run, cmd) }
+
+ let(:stubbed_shell_out) { fail NotImplemented, 'Must declare let(:stubbed_shell_out)' }
+ let(:shell_out) { Mixlib::ShellOut.new(cmd) }
+
+ let(:with_valid_exe_at_location) { lambda { |s| s.stub!(:find_exe_at_location).and_return(executable_path) } }
+ let(:with_invalid_exe_at_location) { lambda { |s| s.stub!(:find_exe_at_location).and_return(nil) } }
+
+ context 'with batch files' do
+ let(:stubbed_shell_out) { shell_out.tap(&with_valid_exe_at_location) }
+ let(:cmd_invocation) { "cmd /c \"#{cmd}\"" }
+ let(:cmd_exe) { "C:\\Windows\\system32\\cmd.exe" }
+ let(:cmd) { "#{executable_path}" }
+
+ context 'with .bat file' do
+ let(:executable_path) { '"C:\Program Files\Application\Start.bat"' }
+
+ # Examples taken from: https://github.com/opscode/mixlib-shellout/pull/2#issuecomment-4825574
+ context 'with executable path enclosed in double quotes' do
+
+ it 'should use specified batch file' do
+ should eql([cmd_exe, cmd_invocation])
+ end
+
+ context 'with arguments' do
+ let(:cmd) { "#{executable_path} arguments" }
+
+ it 'should use specified executable' do
+ should eql([cmd_exe, cmd_invocation])
+ end
+ end
+
+ context 'with quoted arguments' do
+ let(:cmd) { "#{executable_path} /i \"C:\Program Files (x86)\NUnit 2.6\bin\framework\nunit.framework.dll\"" }
+
+ it 'should use specified executable' do
+ should eql([cmd_exe, cmd_invocation])
+ end
+ end
+ end
+ end
+
+ context 'with .cmd file' do
+ let(:executable_path) { '"C:\Program Files\Application\Start.cmd"' }
+
+ # Examples taken from: https://github.com/opscode/mixlib-shellout/pull/2#issuecomment-4825574
+ context 'with executable path enclosed in double quotes' do
+
+ it 'should use specified batch file' do
+ should eql([cmd_exe, cmd_invocation])
+ end
+
+ context 'with arguments' do
+ let(:cmd) { "#{executable_path} arguments" }
+
+ it 'should use specified executable' do
+ should eql([cmd_exe, cmd_invocation])
+ end
+ end
+
+ context 'with quoted arguments' do
+ let(:cmd) { "#{executable_path} /i \"C:\Program Files (x86)\NUnit 2.6\bin\framework\nunit.framework.dll\"" }
+
+ it 'should use specified executable' do
+ should eql([cmd_exe, cmd_invocation])
+ end
+ end
+ end
+
+ end
+ end
+
+ context 'with valid executable at location' do
+ let(:stubbed_shell_out) { shell_out.tap(&with_valid_exe_at_location) }
+
+ # Examples taken from: https://github.com/opscode/mixlib-shellout/pull/2#issuecomment-4825574
+ context 'with executable path enclosed in double quotes' do
+ let(:cmd) { "#{executable_path}" }
+ let(:executable_path) { '"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe"' }
+
+ it 'should use specified executable' do
+ should eql([executable_path, cmd])
+ end
+
+ context 'with arguments' do
+ let(:cmd) { "#{executable_path} arguments" }
+
+ it 'should use specified executable' do
+ should eql([executable_path, cmd])
+ end
+ end
+
+ context 'with quoted arguments' do
+ let(:cmd) { "#{executable_path} /i \"C:\Program Files (x86)\NUnit 2.6\bin\framework\nunit.framework.dll\"" }
+
+ it 'should use specified executable' do
+ should eql([executable_path, cmd])
+ end
+ end
+ end
+
+ end
+ end
+ end
+end