summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-02-06 15:15:41 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2017-02-07 11:27:09 -0800
commitb7af0810fc7c8437585887dd3abf1b62dc773818 (patch)
tree61679f62c441e56fa9d46f34dd5d31caa286732b
parente1f1ba4c9c5a802c0f50b4d5e53b26a5da982c20 (diff)
downloadchef-b7af0810fc7c8437585887dd3abf1b62dc773818.tar.gz
fix return of which()
also clean up a confusing spec test Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/mixin/which.rb2
-rw-r--r--spec/unit/util/selinux_spec.rb15
2 files changed, 3 insertions, 14 deletions
diff --git a/lib/chef/mixin/which.rb b/lib/chef/mixin/which.rb
index 92934ce485..a81aacd89b 100644
--- a/lib/chef/mixin/which.rb
+++ b/lib/chef/mixin/which.rb
@@ -19,7 +19,7 @@ class Chef
module Mixin
module Which
def which(*cmds, extra_path: nil, &block)
- where(*cmds, extra_path: extra_path, &block).first
+ where(*cmds, extra_path: extra_path, &block).first || false
end
def where(*cmds, extra_path: nil, &block)
diff --git a/spec/unit/util/selinux_spec.rb b/spec/unit/util/selinux_spec.rb
index 609ff02215..69d1ccdb1f 100644
--- a/spec/unit/util/selinux_spec.rb
+++ b/spec/unit/util/selinux_spec.rb
@@ -148,21 +148,10 @@ describe Chef::Util::Selinux do
end
describe "when restorecon doesn't exist on the system" do
- before do
- allow(File).to receive(:executable?) do |file_path|
- expect(file_path.end_with?("restorecon")).to be_truthy
- false
- end
- end
-
it "should log a warning message" do
- log = [ ]
- allow(Chef::Log).to receive(:warn) do |message|
- log << message
- end
-
+ allow(File).to receive(:executable?).with(/restorecon$/).and_return(false)
+ expect(Chef::Log).to receive(:warn).with(/Can not find 'restorecon' on the system. Skipping selinux security context restore./).at_least(:once)
@test_instance.restore_security_context(path)
- expect(log).not_to be_empty
expect(File).not_to receive(:executable?)
@test_instance.restore_security_context(path)
end