diff options
author | Ho-Sheng Hsiao <hosheng.hsiao@gmail.com> | 2012-04-02 17:48:16 -0400 |
---|---|---|
committer | Ho-Sheng Hsiao <hosh@opscode.com> | 2012-05-10 14:51:43 -0400 |
commit | 146de90bee9a19f97a2b13595d39cbd99cb7eb77 (patch) | |
tree | 22d6703d8cc9dc64d98bd56316e336327ba56ba3 /spec | |
parent | b9df898902417866409e74d1e6098ca3dbe01f3d (diff) | |
download | mixlib-shellout-146de90bee9a19f97a2b13595d39cbd99cb7eb77.tar.gz |
[CHEF-2994][WINDOWS] Fixed Utils.which()
- Factored out Utils.should_run_under_cmd? (simple case)
Diffstat (limited to 'spec')
-rw-r--r-- | spec/mixlib/shellout/windows_spec.rb | 30 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 |
2 files changed, 32 insertions, 0 deletions
diff --git a/spec/mixlib/shellout/windows_spec.rb b/spec/mixlib/shellout/windows_spec.rb index 1cc6ff3..4e6b83f 100644 --- a/spec/mixlib/shellout/windows_spec.rb +++ b/spec/mixlib/shellout/windows_spec.rb @@ -2,6 +2,36 @@ require 'spec_helper' describe 'Mixlib::ShellOut::Windows', :windows_only => true do + describe 'Utils' do + describe '.should_run_under_cmd?' do + subject { Mixlib::ShellOut::Windows::Utils.should_run_under_cmd?(command) } + + def self.with_command(_command, &example) + context "with command: #{_command}" do + let(:command) { _command } + it(&example) + end + end + + with_command(%q{ruby -e 'prints "foobar"'}) { should_not be_true } + + # https://github.com/opscode/mixlib-shellout/pull/2#issuecomment-4825574 + with_command(%q{"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe" /i "C:\Program Files (x86)\NUnit 2.6\bin\framework\nunit.framework.dll"}) { should_not be_true } + + with_command(%q{ruby -e 'exit 1' | ruby -e 'exit 0'}) { should be_true } + with_command(%q{ruby -e 'exit 1' > out.txt}) { should be_true } + with_command(%q{ruby -e 'exit 1' > out.txt 2>&1}) { should be_true } + with_command(%q{ruby -e 'exit 1' < in.txt}) { should be_true } + with_command(%q{ruby -e 'exit 1' || ruby -e 'exit 0'}) { should be_true } + with_command(%q{ruby -e 'exit 1' && ruby -e 'exit 0'}) { should be_true } + with_command(%q{@echo TRUE}) { should be_true } + with_command(%q{echo %PATH%}) { should be_true } + + # TODO: It would be awesome if it can detect quoted special characters + with_command(%q{echo "ruby -e 'exit 1' || ruby -e 'exit 0'"}) { should be_true } + end + end + # Caveat: Private API methods are subject to change without notice. # Monkeypatch at your own risk. context 'for private API methods' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6f400d9..cb6d017 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,6 +8,8 @@ require 'timeout' require 'ap' +WATCH = lambda { |x| ap x } unless defined?(WATCH) + # Load everything from spec/support # Do not change the gsub. Dir["spec/support/**/*.rb"].map { |f| f.gsub(%r{.rb$}, '') }.each { |f| require f } |