Skip to content

Commit

Permalink
mas v1.8.7/v1.9.0/v2.0.0 updates
Browse files Browse the repository at this point in the history
- Once the next version of `mas` is released: we can again rely on
  `mas outdated`.
- `mas_signedin?` hasn't worked for a long time and isn't coming back
   so just delete the code to simplify things.
  • Loading branch information
MikeMcQuaid committed Feb 20, 2024
1 parent d3cf1e1 commit 696b760
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 70 deletions.
8 changes: 0 additions & 8 deletions lib/bundle/bundle.rb
Expand Up @@ -33,14 +33,6 @@ def whalebrew_installed?
@whalebrew_installed ||= which_formula("whalebrew")
end

def mas_signedin?
# mas account doesn't work on Monterey (yet)
# https://github.com/mas-cli/mas/issues/417#issuecomment-957963271
return true if MacOS.version >= :monterey

Kernel.system "mas account &>/dev/null"
end

def cask_installed?
@cask_installed ||= File.directory?("#{HOMEBREW_PREFIX}/Caskroom") &&
(File.directory?("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-cask") ||
Expand Down
23 changes: 7 additions & 16 deletions lib/bundle/mac_app_store_installer.rb
Expand Up @@ -24,11 +24,6 @@ def preinstall(name, id, no_upgrade: false, verbose: false)
return false
end

unless Bundle.mas_signedin?
puts "Not signed in to Mac App Store." if verbose
raise "Unable to install #{name} app. mas not signed in to Mac App Store."
end

true
end

Expand Down Expand Up @@ -70,17 +65,13 @@ def installed_app_ids
end

def outdated_app_ids
[]

# TODO: can't be trusted right now.
# Uncomment when https://github.com/mas-cli/mas/pull/496 is merged.
# @outdated_app_ids ||= if Bundle.mas_installed?
# `mas outdated 2>/dev/null`.split("\n").map do |app|
# app.split(" ", 2).first.to_i
# end
# else
# []
# end
@outdated_app_ids ||= if Bundle.mas_installed?
`mas outdated 2>/dev/null`.split("\n").map do |app|
app.split(" ", 2).first.to_i
end
else
[]
end
end
end
end
74 changes: 28 additions & 46 deletions spec/bundle/mac_app_store_installer_spec.rb
Expand Up @@ -41,64 +41,46 @@
allow(Bundle).to receive(:mas_installed?).and_return(true)
end

# TODO: can't be trusted right now.
# Uncomment when https://github.com/mas-cli/mas/pull/496 is merged.
# describe ".outdated_app_ids" do
# it "returns app ids" do
# expect(described_class).to receive(:`).and_return("foo 123")
# described_class.reset!
# described_class.outdated_app_ids
# end
# end

context "when mas is not signed in" do
it "outputs an error" do
allow(described_class).to receive_messages(installed_app_ids: [123], outdated_app_ids: [123])
allow(MacOS).to receive(:version).and_return(:big_sur)
expect(Kernel).to receive(:system).with("mas account &>/dev/null").and_return(false)
expect { described_class.preinstall("foo", 123) }.to raise_error(RuntimeError)
describe ".outdated_app_ids" do
it "returns app ids" do
expect(described_class).to receive(:`).and_return("foo 123")
described_class.reset!
described_class.outdated_app_ids
end
end

context "when mas is signed in" do
context "when app is installed" do
before do
allow(Bundle).to receive(:mas_signedin?).and_return(true)
allow(described_class).to receive(:outdated_app_ids).and_return([])
allow(described_class).to receive(:installed_app_ids).and_return([123])
end

context "when app is installed" do
before do
allow(described_class).to receive(:installed_app_ids).and_return([123])
end

it "skips" do
expect(Bundle).not_to receive(:system)
expect(described_class.preinstall("foo", 123)).to be(false)
end
it "skips" do
expect(Bundle).not_to receive(:system)
expect(described_class.preinstall("foo", 123)).to be(false)
end
end

context "when app is outdated" do
before do
allow(described_class).to receive_messages(installed_app_ids: [123], outdated_app_ids: [123])
end
context "when app is outdated" do
before do
allow(described_class).to receive_messages(installed_app_ids: [123], outdated_app_ids: [123])
end

it "upgrades" do
expect(Bundle).to receive(:system).with("mas", "upgrade", "123", verbose: false).and_return(true)
expect(described_class.preinstall("foo", 123)).to be(true)
expect(described_class.install("foo", 123)).to be(true)
end
it "upgrades" do
expect(Bundle).to receive(:system).with("mas", "upgrade", "123", verbose: false).and_return(true)
expect(described_class.preinstall("foo", 123)).to be(true)
expect(described_class.install("foo", 123)).to be(true)
end
end

context "when app is not installed" do
before do
allow(described_class).to receive(:installed_app_ids).and_return([])
end
context "when app is not installed" do
before do
allow(described_class).to receive(:installed_app_ids).and_return([])
end

it "installs app" do
expect(Bundle).to receive(:system).with("mas", "install", "123", verbose: false).and_return(true)
expect(described_class.preinstall("foo", 123)).to be(true)
expect(described_class.install("foo", 123)).to be(true)
end
it "installs app" do
expect(Bundle).to receive(:system).with("mas", "install", "123", verbose: false).and_return(true)
expect(described_class.preinstall("foo", 123)).to be(true)
expect(described_class.install("foo", 123)).to be(true)
end
end
end
Expand Down

0 comments on commit 696b760

Please sign in to comment.