diff --git a/lib/hbc/cli.rb b/lib/hbc/cli.rb index 91aaa03b348bb..83542f3d04424 100644 --- a/lib/hbc/cli.rb +++ b/lib/hbc/cli.rb @@ -16,6 +16,7 @@ class Hbc::CLI; end require 'hbc/cli/info' require 'hbc/cli/install' require 'hbc/cli/list' +require 'hbc/cli/outdated' require 'hbc/cli/search' require 'hbc/cli/uninstall' require 'hbc/cli/update' diff --git a/lib/hbc/cli/outdated.rb b/lib/hbc/cli/outdated.rb new file mode 100644 index 0000000000000..ea49796a46db6 --- /dev/null +++ b/lib/hbc/cli/outdated.rb @@ -0,0 +1,9 @@ +class Hbc::CLI::Outdated < Hbc::CLI::Base + def self.help + 'lists installed casks that have an upgraded version available' + end + + def self.run(*args) + puts Hbc.outdated.map(&:to_s) + end +end diff --git a/lib/hbc/scopes.rb b/lib/hbc/scopes.rb index d0489738fb1fc..ab0c1b33a1f7e 100644 --- a/lib/hbc/scopes.rb +++ b/lib/hbc/scopes.rb @@ -20,12 +20,6 @@ def all_tapped_cask_dirs @all_tapped_cask_dirs end - def reset_all_tapped_cask_dirs - # The memoized value should be reset when a Tap is added/removed - # (which is a rare event in our codebase). - @all_tapped_cask_dirs = nil - end - def all_tokens cask_tokens = all_tapped_cask_dirs.map { |d| Dir.glob d.join('*.rb') }.flatten cask_tokens.map { |c| @@ -58,5 +52,9 @@ def installed end end end + + def outdated + installed.select(&:outdated?) + end end end diff --git a/spec/cask/cli/outdated_spec.rb b/spec/cask/cli/outdated_spec.rb new file mode 100644 index 0000000000000..8f7380d23a9d0 --- /dev/null +++ b/spec/cask/cli/outdated_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe Hbc::CLI::Outdated do + describe '.help' do + it 'describes outdated properly' do + expect(described_class.help).to eq('lists installed casks that have an upgraded version available') + end + end + + describe '.run' do + let(:outdated_casks) {[ + double('Cask', to_s: 'pretty-old'), + double('Cask', to_s: 'cask-needs-upgrade-badly'), + ]} + before do + allow(Hbc).to receive(:outdated) { outdated_casks } + end + it 'lists the outdated casks' do + expect { + described_class.run + }.to output(<<-OUTPUT.gsub(/ */, '')).to_stdout + pretty-old + cask-needs-upgrade-badly + OUTPUT + end + end +end diff --git a/spec/cask/scopes_spec.rb b/spec/cask/scopes_spec.rb index 602a6d79e5d32..db30a1ea35e81 100644 --- a/spec/cask/scopes_spec.rb +++ b/spec/cask/scopes_spec.rb @@ -41,4 +41,18 @@ expect(Hbc).to have_received(:load).with(absolute_path_to_cask) end end + + describe 'outdated' do + let(:installed_casks) {[ + double('Cask', name: 'up-to-date', outdated?: false), + double('Cask', name: 'pretty-old', outdated?: true), + ]} + before do + allow(Hbc).to receive(:installed) { installed_casks } + end + + it 'returns the list of casks whose installed version does not match the latest available version' do + expect(Hbc.outdated.map(&:name)).to eq(%w[pretty-old]) + end + end end