diff options
-rw-r--r-- | lib/chef/provider/package/homebrew.rb | 10 | ||||
-rw-r--r-- | spec/unit/provider/package/homebrew_spec.rb | 26 |
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/chef/provider/package/homebrew.rb b/lib/chef/provider/package/homebrew.rb index 822f4c8a42..1b407a1901 100644 --- a/lib/chef/provider/package/homebrew.rb +++ b/lib/chef/provider/package/homebrew.rb @@ -94,7 +94,15 @@ class Chef # that brew thinks is linked as the current version. # def current_installed_version - brew_info['keg_only'] ? brew_info['installed'].last['version'] : brew_info['linked_keg'] + if brew_info['keg_only'] + if brew_info['installed'].empty? + nil + else + brew_info['installed'].last['version'] + end + else + brew_info['linked_keg'] + end end # Packages (formula) available to install should have a diff --git a/spec/unit/provider/package/homebrew_spec.rb b/spec/unit/provider/package/homebrew_spec.rb index dccd8edf11..d01d455b09 100644 --- a/spec/unit/provider/package/homebrew_spec.rb +++ b/spec/unit/provider/package/homebrew_spec.rb @@ -93,6 +93,27 @@ describe Chef::Provider::Package::Homebrew do } end + let(:keg_only_uninstalled_brew_info) do + { + 'name' => 'emacs-kegger', + 'homepage' => 'http://www.gnu.org/software/emacs/', + 'versions' => { + 'stable' => '24.3-keggy', + 'bottle' => false, + 'devel' => nil, + 'head' => 'HEAD' + }, + 'revision' => 0, + 'installed' => [], + 'linked_keg' => nil, + 'keg_only' => true, + 'dependencies' => [], + 'conflicts_with' => [], + 'caveats' => '', + 'options' => [] + } + end + before(:each) do end @@ -141,6 +162,11 @@ describe Chef::Provider::Package::Homebrew do allow(provider).to receive(:brew_info).and_return(uninstalled_brew_info) expect(provider.current_installed_version).to be_nil end + + it 'returns nil if the package is keg only and not installed' do + allow(provider).to receive(:brew_info).and_return(keg_only_uninstalled_brew_info) + expect(provider.current_installed_version).to be_nil + end end describe 'brew' do |