summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2014-12-14 19:52:37 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2014-12-15 10:37:53 -0800
commite82d582a8e8fa753c0b8f7d3b6fddd6c6aac02f2 (patch)
tree97c77ea76e2775d96aba444f5a9af5e8ab17b359
parent41d8720692f2ea0cb24e4f2049f9b0a1208d288f (diff)
downloadchef-e82d582a8e8fa753c0b8f7d3b6fddd6c6aac02f2.tar.gz
Merge pull request #2629 from opscode/jdm/shellout-spec
Cleanup Mixin:ShellOut use/specs
-rw-r--r--spec/support/platform_helpers.rb7
-rw-r--r--spec/unit/mixin/shell_out_spec.rb79
2 files changed, 44 insertions, 42 deletions
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index 8d17af3993..2f21fe4401 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -1,7 +1,10 @@
require 'fcntl'
require 'chef/mixin/shell_out'
-include Chef::Mixin::ShellOut
+
+class ShellHelpers
+ extend Chef::Mixin::ShellOut
+end
def ruby_gte_20?
RUBY_VERSION.to_f >= 2.0
@@ -78,7 +81,7 @@ end
def mac_osx_106?
if File.exists? "/usr/bin/sw_vers"
- result = shell_out("/usr/bin/sw_vers")
+ result = ShellHelpers.shell_out("/usr/bin/sw_vers")
result.stdout.each_line do |line|
if line =~ /^ProductVersion:\s10.6.*$/
return true
diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index 38a63a32ee..09ab6e8a7f 100644
--- a/spec/unit/mixin/shell_out_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -23,10 +23,10 @@
require 'spec_helper'
describe Chef::Mixin::ShellOut do
- include Chef::Mixin::ShellOut
-
+ let(:shell_out_class) { Class.new { include Chef::Mixin::ShellOut } }
+ subject(:shell_out_obj) { shell_out_class.new }
describe '#run_command_compatible_options' do
- subject { run_command_compatible_options(command_args) }
+ subject { shell_out_obj.run_command_compatible_options(command_args) }
let(:command_args) { [ cmd, options ] }
let(:cmd) { "echo '#{rand(1000)}'" }
@@ -117,7 +117,6 @@ describe Chef::Mixin::ShellOut do
ENV.update(@original_env)
end
- let(:shell_out) { Chef::Mixin::ShellOut }
let(:cmd) { "echo '#{rand(1000)}'" }
describe "#shell_out" do
@@ -126,30 +125,30 @@ describe Chef::Mixin::ShellOut do
describe "and environment is an option" do
it "should not change environment['LC_ALL'] when set to nil" do
options = { :environment => { 'LC_ALL' => nil } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out(cmd, options)
end
it "should not change environment['LC_ALL'] when set to non-nil" do
options = { :environment => { 'LC_ALL' => 'en_US.UTF-8' } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out(cmd, options)
end
it "should set environment['LC_ALL'] to 'en_US.UTF-8' when 'LC_ALL' not present" do
options = { :environment => { 'HOME' => '/Users/morty' } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, {
:environment => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
}).and_return(true)
- shell_out.shell_out(cmd, options)
+ shell_out_obj.shell_out(cmd, options)
end
it "should not mutate the options hash when it adds LC_ALL" do
options = { :environment => { 'HOME' => '/Users/morty' } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, {
:environment => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
}).and_return(true)
- shell_out.shell_out(cmd, options)
+ shell_out_obj.shell_out(cmd, options)
expect(options[:environment].has_key?('LC_ALL')).to be false
end
end
@@ -157,30 +156,30 @@ describe Chef::Mixin::ShellOut do
describe "and env is an option" do
it "should not change env when set to nil" do
options = { :env => { 'LC_ALL' => nil } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out(cmd, options)
end
it "should not change env when set to non-nil" do
options = { :env => { 'LC_ALL' => 'de_DE.UTF-8'}}
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out(cmd, options)
end
it "should set env['LC_ALL'] to 'en_US.UTF-8' when 'LC_ALL' not present" do
options = { :env => { 'HOME' => '/Users/morty' } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, {
:env => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
}).and_return(true)
- shell_out.shell_out(cmd, options)
+ shell_out_obj.shell_out(cmd, options)
end
it "should not mutate the options hash when it adds LC_ALL" do
options = { :env => { 'HOME' => '/Users/morty' } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, {
:env => { 'HOME' => '/Users/morty', 'LC_ALL' => Chef::Config[:internal_locale] },
}).and_return(true)
- shell_out.shell_out(cmd, options)
+ shell_out_obj.shell_out(cmd, options)
expect(options[:env].has_key?('LC_ALL')).to be false
end
end
@@ -188,20 +187,20 @@ describe Chef::Mixin::ShellOut do
describe "and no env/environment option is present" do
it "should add environment option and set environment['LC_ALL'] to 'en_US.UTF_8'" do
options = { :user => 'morty' }
- expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, {
:user => 'morty', :environment => { 'LC_ALL' => Chef::Config[:internal_locale] },
}).and_return(true)
- shell_out.shell_out(cmd, options)
+ shell_out_obj.shell_out(cmd, options)
end
end
end
describe "when the last argument is not a Hash" do
it "should add environment options and set environment['LC_ALL'] to 'en_US.UTF-8'" do
- expect(shell_out).to receive(:shell_out_command).with(cmd, {
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, {
:environment => { 'LC_ALL' => Chef::Config[:internal_locale] },
}).and_return(true)
- shell_out.shell_out(cmd)
+ shell_out_obj.shell_out(cmd)
end
end
@@ -213,56 +212,56 @@ describe Chef::Mixin::ShellOut do
describe "and environment is an option" do
it "should not change environment['LC_ALL'] when set to nil" do
options = { :environment => { 'LC_ALL' => nil } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out_with_systems_locale(cmd, options)
end
it "should not change environment['LC_ALL'] when set to non-nil" do
options = { :environment => { 'LC_ALL' => 'en_US.UTF-8' } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out_with_systems_locale(cmd, options)
end
it "should no longer set environment['LC_ALL'] to nil when 'LC_ALL' not present" do
options = { :environment => { 'HOME' => '/Users/morty' } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out_with_systems_locale(cmd, options)
end
end
describe "and env is an option" do
it "should not change env when set to nil" do
options = { :env => { 'LC_ALL' => nil } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out_with_systems_locale(cmd, options)
end
it "should not change env when set to non-nil" do
options = { :env => { 'LC_ALL' => 'en_US.UTF-8'}}
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out_with_systems_locale(cmd, options)
end
it "should no longer set env['LC_ALL'] to nil when 'LC_ALL' not present" do
options = { :env => { 'HOME' => '/Users/morty' } }
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out_with_systems_locale(cmd, options)
end
end
describe "and no env/environment option is present" do
it "should no longer add environment option and set environment['LC_ALL'] to nil" do
options = { :user => 'morty' }
- expect(shell_out).to receive(:shell_out_command).with(cmd, options).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd, options)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ shell_out_obj.shell_out_with_systems_locale(cmd, options)
end
end
end
describe "when the last argument is not a Hash" do
it "should no longer add environment options and set environment['LC_ALL'] to nil" do
- expect(shell_out).to receive(:shell_out_command).with(cmd).and_return(true)
- shell_out.shell_out_with_systems_locale(cmd)
+ expect(shell_out_obj).to receive(:shell_out_command).with(cmd).and_return(true)
+ shell_out_obj.shell_out_with_systems_locale(cmd)
end
end
end