summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2014-06-25 09:16:22 -0700
committerClaire McQuin <claire@getchef.com>2014-06-27 12:43:54 -0700
commitc94c7f4a3240531a15d85b9fca732adff5e47838 (patch)
tree35922d961021ccaebc9196de5d12b17ebe93b3e9
parentb4ab3059da0b0be83525298bc7db9c64ebee2573 (diff)
downloadchef-c94c7f4a3240531a15d85b9fca732adff5e47838.tar.gz
Fix shell_out_with_systems_locale logic, add specs.
-rw-r--r--lib/chef/mixin/shell_out.rb6
-rw-r--r--spec/unit/mixin/shell_out_spec.rb58
2 files changed, 61 insertions, 3 deletions
diff --git a/lib/chef/mixin/shell_out.rb b/lib/chef/mixin/shell_out.rb
index 871a11749e..3f8b37a199 100644
--- a/lib/chef/mixin/shell_out.rb
+++ b/lib/chef/mixin/shell_out.rb
@@ -46,11 +46,11 @@ class Chef
def shell_out_with_systems_locale(*command_args)
if command_args.last.is_a?(Hash)
- command_args[:environment] ||= {}
- command_args[:environment]['LC_ALL'] ||= nil
+ command_args.last[:environment] ||= {}
+ command_args.last[:environment]['LC_ALL'] ||= ENV['LC_ALL']
shell_out(*command_args)
else
- shell_out(*command_args, :environment => {'LC_ALL' => nil})
+ shell_out(*command_args, :environment => {'LC_ALL' => ENV['LC_ALL']})
end
end
diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index f325f687d9..00725b235c 100644
--- a/spec/unit/mixin/shell_out_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -104,6 +104,64 @@ describe Chef::Mixin::ShellOut do
should_emit_deprecation_warning_about :command_log_prepend, :log_tag
end
+ end
+
+ describe "#shell_out_with_systems_locale" do
+ let(:shell_out) { Chef::Mixin::ShellOut }
+
+ describe "when the last argument is a Hash" do
+ let(:cmd) { "echo '#{rand(1000)}'" }
+
+ describe "and environment is a key" do
+ let(:options) { { :environment => environment } }
+ describe "and 'LC_ALL' is an :environment key" do
+ let(:environment) { { 'LC_ALL' => 'C' } }
+
+ it "should not modify :environment['LC_ALL']" do
+ shell_out.should_receive(:shell_out).with(cmd, options).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd, options)
+ end
+ end
+
+ describe "and 'LC_ALL' is not an :environment key" do
+ let(:environment) { { 'USER' => 'morty' } }
+
+ it "should set :environment['LC_ALL'] => nil" do
+ shell_out.should_receive(:shell_out).with(
+ cmd,
+ { :environment => { 'USER' => 'morty',
+ 'LC_ALL' => ENV['LC_ALL'] } }
+ ).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd, options)
+ end
+ end
+ end
+
+ describe "and :environment is not a key" do
+ let(:options) { { :user => 'morty' } }
+
+ it "should add :environment => { 'LC_ALL' => nil }" do
+ shell_out.should_receive(:shell_out).with(
+ cmd,
+ { :user => 'morty',
+ :environment => { 'LC_ALL' => ENV['LC_ALL'] } }
+ ).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd, options)
+ end
+ end
+ end
+
+ describe "when the last argument is not a Hash" do
+ let(:cmd) { "echo '#{rand(1000)}'" }
+
+ it "should add :environment => {'LC_ALL' => nil} to the command args" do
+ shell_out.should_receive(:shell_out).with(
+ cmd,
+ { :environment => { 'LC_ALL' => ENV['LC_ALL'] } }
+ ).and_return(true)
+ shell_out.shell_out_with_systems_locale(cmd)
+ end
+ end
end
end