diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-03-30 11:46:27 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-03-31 10:51:50 -0700 |
commit | 55a3745c827093927af40a938d7718e7c2df041a (patch) | |
tree | 4b3cdd6abc3bebe52be4978d8547beae3562762b | |
parent | 17323447548807703ef2b39607ee62db4f6221e8 (diff) | |
download | chef-55a3745c827093927af40a938d7718e7c2df041a.tar.gz |
Switch the array format of shell_out and add a test
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/resource/build_essential.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource/build_essential_spec.rb | 26 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb index a8bcefe27f..1c0d060550 100644 --- a/lib/chef/resource/build_essential.rb +++ b/lib/chef/resource/build_essential.rb @@ -134,7 +134,7 @@ class Chef # # @return [true, false] def xcode_cli_installed? - cmd = shell_out("pkgutil --pkgs=com.apple.pkg.CLTools_Executables") + cmd = shell_out("pkgutil", "--pkgs=com.apple.pkg.CLTools_Executables") # pkgutil returns an error if the package isn't found aka not installed cmd.error? ? false : true end diff --git a/spec/unit/resource/build_essential_spec.rb b/spec/unit/resource/build_essential_spec.rb index 0043b08a5c..ae81da7503 100644 --- a/spec/unit/resource/build_essential_spec.rb +++ b/spec/unit/resource/build_essential_spec.rb @@ -19,7 +19,19 @@ require "spec_helper" describe Chef::Resource::BuildEssential do - let(:resource) { Chef::Resource::BuildEssential.new("foo") } + let(:node) { Chef::Node.new } + let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:run_context) { Chef::RunContext.new(node, {}, events) } + let(:resource) { Chef::Resource::BuildEssential.new("foo", run_context) } + let(:provider) { resource.provider_for_action(:install) } + + let(:pkgutil_cli_exists) do + double("shell_out", stdout: "com.apple.pkg.CLTools_Executables", exitstatus: 0, error?: false) + end + + let(:pkgutil_cli_doesnt_exist) do + double("shell_out", exitstatus: 1, error?: true) + end it "has a resource name of :build_essential" do expect(resource.resource_name).to eql(:build_essential) @@ -40,4 +52,16 @@ describe Chef::Resource::BuildEssential do expect(resource.name).to eql("") end end + + describe "#xcode_cli_installed?" do + it "returns true if the pkgutil lists the package" do + allow(provider).to receive(:shell_out).with("pkgutil", "--pkgs=com.apple.pkg.CLTools_Executables").and_return(pkgutil_cli_exists) + expect(provider.xcode_cli_installed?).to eql(true) + end + + it "returns false if the pkgutil doesn't list the package" do + allow(provider).to receive(:shell_out).with("pkgutil", "--pkgs=com.apple.pkg.CLTools_Executables").and_return(pkgutil_cli_doesnt_exist) + expect(provider.xcode_cli_installed?).to eql(false) + end + end end |