summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-07-21 18:08:09 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-07-21 18:08:09 -0700
commit1cc00a22a6b5cdcabb64644ec322c82adafa7681 (patch)
tree7184fecb5d8575e5bf24c060d57c3a8b37e024d3
parent2227059987a81e87763ecca25f3e63519d659e6e (diff)
downloadchef-1cc00a22a6b5cdcabb64644ec322c82adafa7681.tar.gz
fix shell_out specs to use an instance everywhere.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--spec/unit/mixin/shell_out_spec.rb49
1 files changed, 24 insertions, 25 deletions
diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb
index 8c0790a2c4..5880aa2b6a 100644
--- a/spec/unit/mixin/shell_out_spec.rb
+++ b/spec/unit/mixin/shell_out_spec.rb
@@ -24,7 +24,6 @@ require "spec_helper"
require "chef/mixin/path_sanity"
describe Chef::Mixin::ShellOut do
- include ChefUtils::DSL::PathSanity
let(:shell_out_class) { Class.new { include Chef::Mixin::ShellOut } }
subject(:shell_out_obj) { shell_out_class.new }
@@ -57,38 +56,38 @@ describe Chef::Mixin::ShellOut do
describe "and environment is an option" do
it "should not change environment language settings when they are set to nil" do
options = { environment: { "LC_ALL" => nil, "LANGUAGE" => nil, "LANG" => nil, env_path => nil } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, **options).and_return(retobj)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, **options).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should not change environment language settings when they are set to non-nil" do
options = { environment: { "LC_ALL" => "en_US.UTF-8", "LANGUAGE" => "en_US.UTF-8", "LANG" => "en_US.UTF-8", env_path => "foo:bar:baz" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, **options).and_return(retobj)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, **options).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should set environment language settings to the configured internal locale when they are not present" do
options = { environment: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).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],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should not mutate the options hash when it adds language settings" do
options = { environment: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).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],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
expect(options[:environment].key?("LC_ALL")).to be false
@@ -98,38 +97,38 @@ describe Chef::Mixin::ShellOut do
describe "and env is an option" do
it "should not change env when langauge options are set to nil" do
options = { env: { "LC_ALL" => nil, "LANG" => nil, "LANGUAGE" => nil, env_path => nil } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, **options).and_return(retobj)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, **options).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should not change env when language options are set to non-nil" do
options = { env: { "LC_ALL" => "de_DE.UTF-8", "LANG" => "de_DE.UTF-8", "LANGUAGE" => "de_DE.UTF-8", env_path => "foo:bar:baz" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, **options).and_return(retobj)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, **options).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should set environment language settings to the configured internal locale when they are not present" do
options = { env: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).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],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
it "should not mutate the options hash when it adds language settings" do
options = { env: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).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],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
expect(options[:env].key?("LC_ALL")).to be false
@@ -139,13 +138,13 @@ describe Chef::Mixin::ShellOut do
describe "and no env/environment option is present" do
it "should set environment language settings to the configured internal locale" do
options = { user: "morty" }
- expect(Chef::Mixin::ShellOut).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],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd, **options)
end
@@ -154,12 +153,12 @@ describe Chef::Mixin::ShellOut do
describe "when the last argument is not a Hash" do
it "should set environment language settings to the configured internal locale" do
- expect(Chef::Mixin::ShellOut).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],
"LANG" => Chef::Config[:internal_locale],
"LANGUAGE" => Chef::Config[:internal_locale],
- env_path => sanitized_path,
+ env_path => shell_out_obj.sanitized_path,
}).and_return(retobj)
shell_out_obj.send(method, cmd)
end
@@ -173,19 +172,19 @@ 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(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
it "should not change environment['LC_ALL'] when set to non-nil" do
options = { environment: { "LC_ALL" => "en_US.UTF-8" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
it "should no longer set environment['LC_ALL'] to nil when 'LC_ALL' not present" do
options = { environment: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
end
@@ -193,19 +192,19 @@ 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(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
it "should not change env when set to non-nil" do
options = { env: { "LC_ALL" => "en_US.UTF-8" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
it "should no longer set env['LC_ALL'] to nil when 'LC_ALL' not present" do
options = { env: { "HOME" => "/Users/morty" } }
- expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
end
@@ -213,7 +212,7 @@ describe Chef::Mixin::ShellOut do
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(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, options).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd, options).and_return(true)
shell_out_obj.shell_out(cmd, **options, default_env: false)
end
end
@@ -221,7 +220,7 @@ describe Chef::Mixin::ShellOut do
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(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd).and_return(true)
+ expect(shell_out_obj).to receive(:__shell_out_command).with(cmd).and_return(true)
shell_out_obj.shell_out(cmd, default_env: false)
end
end