Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] brew cask outdated #9490

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/hbc/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 9 additions & 0 deletions lib/hbc/cli/outdated.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 4 additions & 6 deletions lib/hbc/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -58,5 +52,9 @@ def installed
end
end
end

def outdated
installed.select(&:outdated?)
end
end
end
27 changes: 27 additions & 0 deletions spec/cask/cli/outdated_spec.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions spec/cask/scopes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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