From ac7cda9de8a41754226894336794b7972d33a1b8 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Mon, 6 Feb 2017 18:36:16 -0800 Subject: add unit tests for `which` behavior Signed-off-by: Lamont Granquist --- lib/chef/mixin/which.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/chef/mixin') diff --git a/lib/chef/mixin/which.rb b/lib/chef/mixin/which.rb index a81aacd89b..faa46b9594 100644 --- a/lib/chef/mixin/which.rb +++ b/lib/chef/mixin/which.rb @@ -25,8 +25,8 @@ class Chef def where(*cmds, extra_path: nil, &block) # NOTE: unnecessarily duplicates function of path_sanity extra_path ||= [ "/bin", "/usr/bin", "/sbin", "/usr/sbin" ] + paths = env_path.split(File::PATH_SEPARATOR) + extra_path cmds.map do |cmd| - paths = ENV["PATH"].split(File::PATH_SEPARATOR) + extra_path paths.map do |path| filename = Chef.path_to(File.join(path, cmd)) filename if valid_executable?(filename, &block) @@ -36,6 +36,11 @@ class Chef private + # for test stubbing + def env_path + ENV["PATH"] + end + def valid_executable?(filename, &block) return false unless File.executable?(filename) && !File.directory?(filename) block ? yield(filename) : true -- cgit v1.2.1