diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index 38c0ceb09a..4336cff60a 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -11,7 +11,7 @@ module Cask extend Searchable include Metadata - attr_reader :token, :sourcefile_path, :config + attr_reader :token, :sourcefile_path def self.each return to_enum unless block_given? @@ -31,7 +31,7 @@ module Cask @tap end - def initialize(token, sourcefile_path: nil, tap: nil, config: Config.global, &block) + def initialize(token, sourcefile_path: nil, tap: nil, config: nil, &block) @token = token @sourcefile_path = sourcefile_path @tap = tap @@ -77,6 +77,14 @@ module Cask metadata_master_container_path.join(*installed_version, "Casks", "#{token}.rb") end + def config + @config ||= Config.for_cask(self) + end + + def config_path + metadata_master_container_path/"dirs.json" + end + def outdated?(greedy = false) !outdated_versions(greedy).empty? end diff --git a/Library/Homebrew/cask/config.rb b/Library/Homebrew/cask/config.rb index 07ffee2ead..ed40737b47 100644 --- a/Library/Homebrew/cask/config.rb +++ b/Library/Homebrew/cask/config.rb @@ -1,12 +1,8 @@ +require "json" + module Cask - class Config - def self.global - @global ||= new - end - - attr_reader :binarydir - - def initialize( + class Config < DelegateClass(Hash) + DEFAULT_DIRS = { appdir: "/Applications", prefpanedir: "~/Library/PreferencePanes", qlplugindir: "~/Library/QuickLook", @@ -19,47 +15,51 @@ module Cask audio_unit_plugindir: "~/Library/Audio/Plug-Ins/Components", vst_plugindir: "~/Library/Audio/Plug-Ins/VST", vst3_plugindir: "~/Library/Audio/Plug-Ins/VST3", - screen_saverdir: "~/Library/Screen Savers" - ) + screen_saverdir: "~/Library/Screen Savers", + }.freeze - self.appdir = appdir - self.prefpanedir = prefpanedir - self.qlplugindir = qlplugindir - self.dictionarydir = dictionarydir - self.fontdir = fontdir - self.colorpickerdir = colorpickerdir - self.servicedir = servicedir - self.input_methoddir = input_methoddir - self.internet_plugindir = internet_plugindir - self.audio_unit_plugindir = audio_unit_plugindir - self.vst_plugindir = vst_plugindir - self.vst3_plugindir = vst3_plugindir - self.screen_saverdir = screen_saverdir - - # `binarydir` is not customisable. - @binarydir = HOMEBREW_PREFIX/"bin" + def self.global + @global ||= new end - [ - :appdir, - :prefpanedir, - :qlplugindir, - :dictionarydir, - :fontdir, - :colorpickerdir, - :servicedir, - :input_methoddir, - :internet_plugindir, - :audio_unit_plugindir, - :vst_plugindir, - :vst3_plugindir, - :screen_saverdir, - ].each do |dir| - attr_reader dir + def self.for_cask(cask) + if cask.config_path.exist? + from_file(cask.config_path) + else + global + end + end + + def self.from_file(path) + config = begin + JSON.parse(File.read(path)) + rescue JSON::ParserError => e + raise e, "Cannot parse #{path}: #{e}", e.backtrace + end + + new(Hash[config.map { |k, v| [k.to_sym, v] }]) + end + + def initialize(**dirs) + super(Hash[DEFAULT_DIRS.map { |(k, v)| [k, Pathname(dirs.fetch(k, v)).expand_path] }]) + end + + def binarydir + @binarydir ||= HOMEBREW_PREFIX/"bin" + end + + DEFAULT_DIRS.keys.each do |dir| + define_method(dir) do + self[dir] + end define_method(:"#{dir}=") do |path| - instance_variable_set(:"@#{dir}", Pathname(path).expand_path) + self[dir] = Pathname(path).expand_path end end + + def write(path) + path.atomic_write(to_json) + end end end diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 5c2b58ebd2..74f1664972 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -39,7 +39,7 @@ module Cask end attr_predicate :binaries?, :force?, :skip_cask_deps?, :require_sha?, - :upgrade?, :verbose?, :installed_as_dependency?, + :reinstall?, :upgrade?, :verbose?, :installed_as_dependency?, :quarantine? def self.print_caveats(cask) @@ -79,7 +79,7 @@ module Cask def install odebug "Cask::Installer#install" - if @cask.installed? && !force? && !@reinstall && !upgrade? + if @cask.installed? && !force? && !reinstall? && !upgrade? raise CaskAlreadyInstalledError, @cask end @@ -87,7 +87,7 @@ module Cask print_caveats fetch - uninstall_existing_cask if @reinstall + uninstall_existing_cask if reinstall? oh1 "Installing Cask #{Formatter.identifier(@cask)}" opoo "macOS's Gatekeeper has been disabled for this Cask" unless quarantine? @@ -209,6 +209,8 @@ module Cask artifact.install_phase(command: @command, verbose: verbose?, force: force?) already_installed_artifacts.unshift(artifact) end + + save_config_file rescue => e begin already_installed_artifacts.each do |artifact| @@ -382,13 +384,23 @@ module Cask old_savedir&.rmtree end + def save_config_file + @cask.config.write(@cask.config_path) + end + def uninstall oh1 "Uninstalling Cask #{Formatter.identifier(@cask)}" uninstall_artifacts(clear: true) + remove_config_file unless reinstall? || upgrade? purge_versioned_files purge_caskroom_path if force? end + def remove_config_file + FileUtils.rm_f @cask.config_path + @cask.config_path.parent.rmdir_if_possible + end + def start_upgrade oh1 "Starting upgrade for Cask #{Formatter.identifier(@cask)}" diff --git a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb index ef929154f6..b2808c420d 100644 --- a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb +++ b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb @@ -11,7 +11,7 @@ describe Cask::Artifact::App, :cask do } let(:source_path) { cask.staged_path.join("Caffeine.app") } - let(:target_path) { Cask::Config.global.appdir.join("AnotherName.app") } + let(:target_path) { cask.config.appdir.join("AnotherName.app") } before do InstallHelper.install_without_artifacts(cask) @@ -58,7 +58,7 @@ describe Cask::Artifact::App, :cask do expect(target_path).to be_a_directory expect(source_path).not_to exist - expect(Cask::Config.global.appdir.join("Caffeine Deluxe.app")).not_to exist + expect(cask.config.appdir.join("Caffeine Deluxe.app")).not_to exist expect(cask.staged_path.join("Caffeine Deluxe.app")).to be_a_directory end diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index 26abb19ad9..14917b4f42 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -5,7 +5,7 @@ describe Cask::Artifact::App, :cask do let(:app) { cask.artifacts.find { |a| a.is_a?(described_class) } } let(:source_path) { cask.staged_path.join("Caffeine.app") } - let(:target_path) { Cask::Config.global.appdir.join("Caffeine.app") } + let(:target_path) { cask.config.appdir.join("Caffeine.app") } let(:install_phase) { app.install_phase(command: command, force: force) } let(:uninstall_phase) { app.uninstall_phase(command: command, force: force) } @@ -53,7 +53,7 @@ describe Cask::Artifact::App, :cask do expect(target_path).to be_a_directory expect(source_path).not_to exist - expect(Cask::Config.global.appdir.join("Caffeine Deluxe.app")).not_to exist + expect(cask.config.appdir.join("Caffeine Deluxe.app")).not_to exist expect(cask.staged_path.join("Caffeine Deluxe.app")).to exist end diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb index bd70904ebc..0aa60c38fe 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -5,7 +5,7 @@ describe Cask::Artifact::Binary, :cask do end } let(:artifacts) { cask.artifacts.select { |a| a.is_a?(described_class) } } - let(:expected_path) { Cask::Config.global.binarydir.join("binary") } + let(:expected_path) { cask.config.binarydir.join("binary") } after do FileUtils.rm expected_path if expected_path.exist? @@ -38,7 +38,7 @@ describe Cask::Artifact::Binary, :cask do end } - let(:expected_path) { Cask::Config.global.binarydir.join("naked_non_executable") } + let(:expected_path) { cask.config.binarydir.join("naked_non_executable") } it "makes the binary executable" do expect(FileUtils).to receive(:chmod) diff --git a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb index ff28392175..83fb55fc58 100644 --- a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb +++ b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb @@ -10,7 +10,7 @@ describe Cask::Artifact::Artifact, :cask do } let(:source_path) { cask.staged_path.join("Caffeine.app") } - let(:target_path) { Cask::Config.global.appdir.join("Caffeine.app") } + let(:target_path) { cask.config.appdir.join("Caffeine.app") } before do InstallHelper.install_without_artifacts(cask) diff --git a/Library/Homebrew/test/cask/artifact/suite_spec.rb b/Library/Homebrew/test/cask/artifact/suite_spec.rb index 87f821aea2..3f4a2d6dc8 100644 --- a/Library/Homebrew/test/cask/artifact/suite_spec.rb +++ b/Library/Homebrew/test/cask/artifact/suite_spec.rb @@ -9,7 +9,7 @@ describe Cask::Artifact::Suite, :cask do end } - let(:target_path) { Cask::Config.global.appdir.join("Caffeine") } + let(:target_path) { cask.config.appdir.join("Caffeine") } let(:source_path) { cask.staged_path.join("Caffeine") } before do diff --git a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb index a5375125ba..7381c832ba 100644 --- a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb +++ b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb @@ -11,10 +11,10 @@ describe Cask::Artifact::App, :cask do } let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") } - let(:target_path_mini) { Cask::Config.global.appdir.join("Caffeine Mini.app") } + let(:target_path_mini) { cask.config.appdir.join("Caffeine Mini.app") } let(:source_path_pro) { cask.staged_path.join("Caffeine Pro.app") } - let(:target_path_pro) { Cask::Config.global.appdir.join("Caffeine Pro.app") } + let(:target_path_pro) { cask.config.appdir.join("Caffeine Pro.app") } before do InstallHelper.install_without_artifacts(cask) @@ -52,7 +52,7 @@ describe Cask::Artifact::App, :cask do expect(target_path_mini).to be_a_directory expect(source_path_mini).not_to exist - expect(Cask::Config.global.appdir.join("Caffeine Deluxe.app")).not_to exist + expect(cask.config.appdir.join("Caffeine Deluxe.app")).not_to exist expect(cask.staged_path.join("Caffeine Deluxe.app")).to exist end diff --git a/Library/Homebrew/test/cask/cmd/install_spec.rb b/Library/Homebrew/test/cask/cmd/install_spec.rb index c3113e1662..1efe513b4c 100644 --- a/Library/Homebrew/test/cask/cmd/install_spec.rb +++ b/Library/Homebrew/test/cask/cmd/install_spec.rb @@ -21,11 +21,12 @@ describe Cask::Cmd::Install, :cask do it "allows staging and activation of multiple Casks at once" do described_class.run("local-transmission", "local-caffeine") - - expect(Cask::CaskLoader.load(cask_path("local-transmission"))).to be_installed - expect(Cask::Config.global.appdir.join("Transmission.app")).to be_a_directory - expect(Cask::CaskLoader.load(cask_path("local-caffeine"))).to be_installed - expect(Cask::Config.global.appdir.join("Caffeine.app")).to be_a_directory + transmission = Cask::CaskLoader.load(cask_path("local-transmission")) + caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) + expect(transmission).to be_installed + expect(transmission.config.appdir.join("Transmission.app")).to be_a_directory + expect(caffeine).to be_installed + expect(caffeine.config.appdir.join("Caffeine.app")).to be_a_directory end it "skips double install (without nuking existing installation)" do diff --git a/Library/Homebrew/test/cask/cmd/list_spec.rb b/Library/Homebrew/test/cask/cmd/list_spec.rb index 2c819fcb30..7d63076e46 100644 --- a/Library/Homebrew/test/cask/cmd/list_spec.rb +++ b/Library/Homebrew/test/cask/cmd/list_spec.rb @@ -80,9 +80,9 @@ describe Cask::Cmd::List, :cask do described_class.run("local-transmission", "local-caffeine") }.to output(<<~EOS).to_stdout ==> Apps - #{Cask::Config.global.appdir.join("Transmission.app")} (#{Cask::Config.global.appdir.join("Transmission.app").abv}) + #{transmission.config.appdir.join("Transmission.app")} (#{transmission.config.appdir.join("Transmission.app").abv}) ==> Apps - Missing App: #{Cask::Config.global.appdir.join("Caffeine.app")} + Missing App: #{caffeine.config.appdir.join("Caffeine.app")} EOS end end diff --git a/Library/Homebrew/test/cask/cmd/uninstall_spec.rb b/Library/Homebrew/test/cask/cmd/uninstall_spec.rb index 215c9f9757..dc6a07e01d 100644 --- a/Library/Homebrew/test/cask/cmd/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cmd/uninstall_spec.rb @@ -51,9 +51,9 @@ describe Cask::Cmd::Uninstall, :cask do described_class.run("local-caffeine", "local-transmission") expect(caffeine).not_to be_installed - expect(Cask::Config.global.appdir.join("Transmission.app")).not_to exist + expect(caffeine.config.appdir.join("Transmission.app")).not_to exist expect(transmission).not_to be_installed - expect(Cask::Config.global.appdir.join("Caffeine.app")).not_to exist + expect(transmission.config.appdir.join("Caffeine.app")).not_to exist end it "calls `uninstall` before removing artifacts" do @@ -69,7 +69,7 @@ describe Cask::Cmd::Uninstall, :cask do }.not_to raise_error expect(cask).not_to be_installed - expect(Cask::Config.global.appdir.join("MyFancyApp.app")).not_to exist + expect(cask.config.appdir.join("MyFancyApp.app")).not_to exist end it "can uninstall Casks when the uninstall script is missing, but only when using `--force`" do @@ -79,7 +79,7 @@ describe Cask::Cmd::Uninstall, :cask do expect(cask).to be_installed - Cask::Config.global.appdir.join("MyFancyApp.app").rmtree + cask.config.appdir.join("MyFancyApp.app").rmtree expect { described_class.run("with-uninstall-script-app") } .to raise_error(Cask::CaskError, /uninstall script .* does not exist/) diff --git a/Library/Homebrew/test/cask/cmd/upgrade_spec.rb b/Library/Homebrew/test/cask/cmd/upgrade_spec.rb index b43bb6c9fa..16b2b82049 100644 --- a/Library/Homebrew/test/cask/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cask/cmd/upgrade_spec.rb @@ -147,7 +147,7 @@ describe Cask::Cmd::Upgrade, :cask do it 'does not include the Casks with "auto_updates true" when the version did not change' do cask = Cask::CaskLoader.load("auto-updates") - cask_path = Cask::Config.global.appdir.join("MyFancyApp.app") + cask_path = cask.config.appdir.join("MyFancyApp.app") expect(cask).to be_installed expect(cask_path).to be_a_directory @@ -188,7 +188,7 @@ describe Cask::Cmd::Upgrade, :cask do it "restores the old Cask if the upgrade failed" do will_fail_if_upgraded = Cask::CaskLoader.load("will-fail-if-upgraded") - will_fail_if_upgraded_path = Cask::Config.global.appdir.join("container") + will_fail_if_upgraded_path = will_fail_if_upgraded.config.appdir.join("container") expect(will_fail_if_upgraded).to be_installed expect(will_fail_if_upgraded_path).to be_a_file @@ -206,7 +206,7 @@ describe Cask::Cmd::Upgrade, :cask do it "does not restore the old Cask if the upgrade failed pre-install" do bad_checksum = Cask::CaskLoader.load("bad-checksum") - bad_checksum_path = Cask::Config.global.appdir.join("Caffeine.app") + bad_checksum_path = bad_checksum.config.appdir.join("Caffeine.app") expect(bad_checksum).to be_installed expect(bad_checksum_path).to be_a_directory diff --git a/Library/Homebrew/test/cask/cmd/zap_spec.rb b/Library/Homebrew/test/cask/cmd/zap_spec.rb index f7071e0e1a..fd646477e8 100644 --- a/Library/Homebrew/test/cask/cmd/zap_spec.rb +++ b/Library/Homebrew/test/cask/cmd/zap_spec.rb @@ -23,8 +23,8 @@ describe Cask::Cmd::Zap, :cask do described_class.run("local-caffeine", "local-transmission") expect(caffeine).not_to be_installed - expect(Cask::Config.global.appdir.join("Caffeine.app")).not_to be_a_symlink + expect(caffeine.config.appdir.join("Caffeine.app")).not_to be_a_symlink expect(transmission).not_to be_installed - expect(Cask::Config.global.appdir.join("Transmission.app")).not_to be_a_symlink + expect(transmission.config.appdir.join("Transmission.app")).not_to be_a_symlink end end diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 0532907f08..d26f237e27 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -468,7 +468,7 @@ describe Cask::DSL, :cask do let(:token) { "appdir-interpolation" } it "is allowed" do - expect(cask.artifacts.first.source).to eq(Cask::Config.global.appdir/"some/path") + expect(cask.artifacts.first.source).to eq(cask.config.appdir/"some/path") end end diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index ac19ed13bd..b9fbbf9171 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -10,7 +10,7 @@ describe Cask::Installer, :cask do Cask::Installer.new(caffeine).install expect(Cask::Caskroom.path.join("local-caffeine", caffeine.version)).to be_a_directory - expect(Cask::Config.global.appdir.join("Caffeine.app")).to be_a_directory + expect(caffeine.config.appdir.join("Caffeine.app")).to be_a_directory end it "works with dmg-based Casks" do @@ -19,7 +19,7 @@ describe Cask::Installer, :cask do Cask::Installer.new(asset).install expect(Cask::Caskroom.path.join("container-dmg", asset.version)).to be_a_directory - expect(Cask::Config.global.appdir.join("container")).to be_a_file + expect(asset.config.appdir.join("container")).to be_a_file end it "works with tar-gz-based Casks" do @@ -28,7 +28,7 @@ describe Cask::Installer, :cask do Cask::Installer.new(asset).install expect(Cask::Caskroom.path.join("container-tar-gz", asset.version)).to be_a_directory - expect(Cask::Config.global.appdir.join("container")).to be_a_file + expect(asset.config.appdir.join("container")).to be_a_file end it "works with xar-based Casks" do @@ -37,7 +37,7 @@ describe Cask::Installer, :cask do Cask::Installer.new(asset).install expect(Cask::Caskroom.path.join("container-xar", asset.version)).to be_a_directory - expect(Cask::Config.global.appdir.join("container")).to be_a_file + expect(asset.config.appdir.join("container")).to be_a_file end it "works with pure bzip2-based Casks" do @@ -46,7 +46,7 @@ describe Cask::Installer, :cask do Cask::Installer.new(asset).install expect(Cask::Caskroom.path.join("container-bzip2", asset.version)).to be_a_directory - expect(Cask::Config.global.appdir.join("container")).to be_a_file + expect(asset.config.appdir.join("container")).to be_a_file end it "works with pure gzip-based Casks" do @@ -55,7 +55,7 @@ describe Cask::Installer, :cask do Cask::Installer.new(asset).install expect(Cask::Caskroom.path.join("container-gzip", asset.version)).to be_a_directory - expect(Cask::Config.global.appdir.join("container")).to be_a_file + expect(asset.config.appdir.join("container")).to be_a_file end it "blows up on a bad checksum" do diff --git a/Library/Homebrew/test/cask/quarantine_spec.rb b/Library/Homebrew/test/cask/quarantine_spec.rb index b56818e228..c46706b00b 100644 --- a/Library/Homebrew/test/cask/quarantine_spec.rb +++ b/Library/Homebrew/test/cask/quarantine_spec.rb @@ -11,13 +11,11 @@ describe Cask::Quarantine, :cask do it "quarantines a nice fresh Cask" do Cask::Cmd::Install.run("local-transmission") - expect( - Cask::CaskLoader.load(cask_path("local-transmission")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("local-transmission")) - expect( - Cask::Config.global.appdir.join("Transmission.app"), - ).to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("Transmission.app")).to be_quarantined end it "quarantines Cask fetches" do @@ -42,83 +40,81 @@ describe Cask::Quarantine, :cask do Cask::Cmd::Install.run("local-transmission") - expect( - Cask::CaskLoader.load(cask_path("local-transmission")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("local-transmission")) - expect(Cask::Config.global.appdir.join("Transmission.app")).to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("Transmission.app")).to be_quarantined end it "quarantines dmg-based Casks" do Cask::Cmd::Install.run("container-dmg") - expect( - Cask::CaskLoader.load(cask_path("container-dmg")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("container-dmg")) - expect(Cask::Config.global.appdir.join("container")).to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("container")).to be_quarantined end it "quarantines tar-gz-based Casks" do Cask::Cmd::Install.run("container-tar-gz") - expect( - Cask::CaskLoader.load(cask_path("container-tar-gz")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("container-tar-gz")) - expect(Cask::Config.global.appdir.join("container")).to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("container")).to be_quarantined end it "quarantines xar-based Casks" do Cask::Cmd::Install.run("container-xar") - expect( - Cask::CaskLoader.load(cask_path("container-xar")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("container-xar")) - expect(Cask::Config.global.appdir.join("container")).to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("container")).to be_quarantined end it "quarantines pure bzip2-based Casks" do Cask::Cmd::Install.run("container-bzip2") - expect( - Cask::CaskLoader.load(cask_path("container-bzip2")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("container-bzip2")) - expect(Cask::Config.global.appdir.join("container")).to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("container")).to be_quarantined end it "quarantines pure gzip-based Casks" do Cask::Cmd::Install.run("container-gzip") - expect( - Cask::CaskLoader.load(cask_path("container-gzip")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("container-gzip")) - expect(Cask::Config.global.appdir.join("container")).to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("container")).to be_quarantined end it "quarantines the pkg in naked-pkg-based Casks" do Cask::Cmd::Install.run("container-pkg") - naked_pkg = Cask::CaskLoader.load(cask_path("container-pkg")) + cask = Cask::CaskLoader.load(cask_path("container-pkg")) - expect(naked_pkg).to be_installed + expect(cask).to be_installed - expect( - Cask::Caskroom.path.join("container-pkg", naked_pkg.version, "container.pkg"), - ).to be_quarantined + expect(cask.staged_path/"container.pkg").to be_quarantined end it "quarantines a nested container" do Cask::Cmd::Install.run("nested-app") - expect( - Cask::CaskLoader.load(cask_path("nested-app")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("nested-app")) - expect(Cask::Config.global.appdir.join("MyNestedApp.app")).to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("MyNestedApp.app")).to be_quarantined end end @@ -126,11 +122,11 @@ describe Cask::Quarantine, :cask do it "does not quarantine even a nice, fresh Cask" do Cask::Cmd::Install.run("local-transmission", "--no-quarantine") - expect( - Cask::CaskLoader.load(cask_path("local-transmission")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("local-transmission")) - expect(Cask::Config.global.appdir.join("Transmission.app")).not_to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("Transmission.app")).not_to be_quarantined end it "does not quarantine Cask fetches" do @@ -155,61 +151,61 @@ describe Cask::Quarantine, :cask do Cask::Cmd::Install.run("local-transmission", "--no-quarantine") - expect( - Cask::CaskLoader.load(cask_path("local-transmission")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("local-transmission")) - expect(Cask::Config.global.appdir.join("Transmission.app")).not_to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("Transmission.app")).not_to be_quarantined end it "does not quarantine dmg-based Casks" do Cask::Cmd::Install.run("container-dmg", "--no-quarantine") - expect( - Cask::CaskLoader.load(cask_path("container-dmg")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("container-dmg")) - expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("container")).not_to be_quarantined end it "does not quarantine tar-gz-based Casks" do Cask::Cmd::Install.run("container-tar-gz", "--no-quarantine") - expect( - Cask::CaskLoader.load(cask_path("container-tar-gz")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("container-tar-gz")) - expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("container")).not_to be_quarantined end it "does not quarantine xar-based Casks" do Cask::Cmd::Install.run("container-xar", "--no-quarantine") - expect( - Cask::CaskLoader.load(cask_path("container-xar")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("container-xar")) - expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("container")).not_to be_quarantined end it "does not quarantine pure bzip2-based Casks" do Cask::Cmd::Install.run("container-bzip2", "--no-quarantine") - expect( - Cask::CaskLoader.load(cask_path("container-bzip2")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("container-bzip2")) - expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("container")).not_to be_quarantined end it "does not quarantine pure gzip-based Casks" do Cask::Cmd::Install.run("container-gzip", "--no-quarantine") - expect( - Cask::CaskLoader.load(cask_path("container-gzip")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("container-gzip")) - expect(Cask::Config.global.appdir.join("container")).not_to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("container")).not_to be_quarantined end it "does not quarantine the pkg in naked-pkg-based Casks" do @@ -227,11 +223,11 @@ describe Cask::Quarantine, :cask do it "does not quarantine a nested container" do Cask::Cmd::Install.run("nested-app", "--no-quarantine") - expect( - Cask::CaskLoader.load(cask_path("nested-app")), - ).to be_installed + cask = Cask::CaskLoader.load(cask_path("nested-app")) - expect(Cask::Config.global.appdir.join("MyNestedApp.app")).not_to be_quarantined + expect(cask).to be_installed + + expect(cask.config.appdir.join("MyNestedApp.app")).not_to be_quarantined end end end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb index f4432f5f06..bb228b66b4 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb @@ -14,7 +14,7 @@ HOMEBREW_CASK_DIRS = { RSpec.shared_context "Homebrew Cask", :needs_macos do before do HOMEBREW_CASK_DIRS.each do |method, path| - allow(Cask::Config.global).to receive(method).and_return(path) + Cask::Config.global.send("#{method}=", path) end end