summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2014-12-12 20:48:21 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2014-12-14 09:29:23 -0800
commit6c1e357dc5e2e9610a6922b5e53c414b5fcb22c5 (patch)
treec306a660d399fd42adc2d9a1ee9867f4621e248a
parent9bd60d864c96a69c5b52621dfe089486c279a424 (diff)
downloadchef-6c1e357dc5e2e9610a6922b5e53c414b5fcb22c5.tar.gz
Cleanup Mixin:ShellOut use/specs
-rw-r--r--spec/support/platform_helpers.rb9
-rw-r--r--spec/unit/mixin/shell_out_spec.rb79
2 files changed, 46 insertions, 42 deletions
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index db0f9ccee4..fa61a52129 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -1,7 +1,12 @@
require 'fcntl'
require 'chef/mixin/shell_out'
-include Chef::Mixin::ShellOut
+
+class ShellHelpers
+ class << self
+ include Chef::Mixin::ShellOut
+ end
+end
def ruby_gte_20?
RUBY_VERSION.to_f >= 2.0
@@ -86,7 +91,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 afce4dc826..c39780b284 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(:dummy_class) { Class.new { include Chef::Mixin::ShellOut } }
+ subject(:dummy_obj) { dummy_class.new }
describe '#run_command_compatible_options' do
- subject { run_command_compatible_options(command_args) }
+ subject { dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_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)
+ dummy_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(dummy_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)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_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)
+ dummy_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(dummy_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)
+ dummy_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(dummy_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)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, {
:environment => { 'LC_ALL' => Chef::Config[:internal_locale] },
}).and_return(true)
- shell_out.shell_out(cmd)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ dummy_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(dummy_obj).to receive(:shell_out_command).with(cmd).and_return(true)
+ dummy_obj.shell_out_with_systems_locale(cmd)
end
end
end