diff --git a/lib/bundle/bundle.rb b/lib/bundle/bundle.rb index 5b638bdf3..5d4ed0d69 100644 --- a/lib/bundle/bundle.rb +++ b/lib/bundle/bundle.rb @@ -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") || diff --git a/lib/bundle/mac_app_store_installer.rb b/lib/bundle/mac_app_store_installer.rb index fba924f4e..2125b32b0 100644 --- a/lib/bundle/mac_app_store_installer.rb +++ b/lib/bundle/mac_app_store_installer.rb @@ -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 @@ -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 diff --git a/spec/bundle/mac_app_store_installer_spec.rb b/spec/bundle/mac_app_store_installer_spec.rb index 46a8c357f..cb21b45f0 100644 --- a/spec/bundle/mac_app_store_installer_spec.rb +++ b/spec/bundle/mac_app_store_installer_spec.rb @@ -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