diff options
| author | Markus Reiter | 2018-01-27 23:49:29 +0100 | 
|---|---|---|
| committer | GitHub | 2018-01-27 23:49:29 +0100 | 
| commit | 9b2610b0adc84db194c5e735f3b385ead5a96fd3 (patch) | |
| tree | d79c6d8aa1a650a3f71312433fabed94fcfdebf6 | |
| parent | d558ec09332c74927dfb9182b19e11c5a73d8b52 (diff) | |
| parent | b4df0246256519cf3879263eb7447cfcd5498491 (diff) | |
| download | brew-9b2610b0adc84db194c5e735f3b385ead5a96fd3.tar.bz2 | |
Merge pull request #3524 from reitermarkus/config
Add `Hbc::Config` class.
28 files changed, 207 insertions, 191 deletions
| diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index db036d279..d865b31f2 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -17,6 +17,7 @@ require "hbc/download_strategy"  require "hbc/exceptions"  require "hbc/installer"  require "hbc/locations" +require "hbc/config"  require "hbc/macos"  require "hbc/pkg"  require "hbc/qualified_token" diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb index f9f736662..077105468 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb @@ -95,10 +95,11 @@ module Hbc          [executable, arguments]        end -      attr_reader :cask +      attr_reader :cask, :config        def initialize(cask)          @cask = cask +        @config = cask.config        end        def to_s diff --git a/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb index 0f37afade..b7df4b0bd 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb @@ -25,7 +25,7 @@ module Hbc          new(cask, source_string, **target_hash)        end -      def self.resolve_target(target) +      def resolve_target(target)          Pathname(target)        end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb index 540699630..9195d889a 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb @@ -18,8 +18,8 @@ module Hbc          new(cask, source_string, **target_hash)        end -      def self.resolve_target(target) -        Hbc.public_send(dirmethod).join(target) +      def resolve_target(target) +        config.public_send(self.class.dirmethod).join(target)        end        attr_reader :source, :target @@ -32,7 +32,7 @@ module Hbc          source = cask.staged_path.join(source)          @source = source          target ||= source.basename -        @target = self.class.resolve_target(target) +        @target = resolve_target(target)        end        def to_a diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index df885371a..681130c1b 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -6,17 +6,18 @@ module Hbc      extend Forwardable      include Metadata -    attr_reader :token, :sourcefile_path +    attr_reader :token, :sourcefile_path, :config      def tap        return super if block_given? # Object#tap        @tap      end -    def initialize(token, sourcefile_path: nil, tap: nil, &block) +    def initialize(token, sourcefile_path: nil, tap: nil, config: Config.global, &block)        @token = token        @sourcefile_path = sourcefile_path        @tap = tap +      @config = config        @dsl = DSL.new(self)        return unless block_given?        @dsl.instance_eval(&block) diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index 5da2a137a..6410af5ae 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -49,19 +49,19 @@ module Hbc      include Options -    option "--appdir=PATH",               ->(value) { Hbc.appdir               = value } -    option "--colorpickerdir=PATH",       ->(value) { Hbc.colorpickerdir       = value } -    option "--prefpanedir=PATH",          ->(value) { Hbc.prefpanedir          = value } -    option "--qlplugindir=PATH",          ->(value) { Hbc.qlplugindir          = value } -    option "--dictionarydir=PATH",        ->(value) { Hbc.dictionarydir        = value } -    option "--fontdir=PATH",              ->(value) { Hbc.fontdir              = value } -    option "--servicedir=PATH",           ->(value) { Hbc.servicedir           = value } -    option "--input_methoddir=PATH",      ->(value) { Hbc.input_methoddir      = value } -    option "--internet_plugindir=PATH",   ->(value) { Hbc.internet_plugindir   = value } -    option "--audio_unit_plugindir=PATH", ->(value) { Hbc.audio_unit_plugindir = value } -    option "--vst_plugindir=PATH",        ->(value) { Hbc.vst_plugindir        = value } -    option "--vst3_plugindir=PATH",       ->(value) { Hbc.vst3_plugindir       = value } -    option "--screen_saverdir=PATH",      ->(value) { Hbc.screen_saverdir      = value } +    option "--appdir=PATH",               ->(value) { Config.global.appdir               = value } +    option "--colorpickerdir=PATH",       ->(value) { Config.global.colorpickerdir       = value } +    option "--prefpanedir=PATH",          ->(value) { Config.global.prefpanedir          = value } +    option "--qlplugindir=PATH",          ->(value) { Config.global.qlplugindir          = value } +    option "--dictionarydir=PATH",        ->(value) { Config.global.dictionarydir        = value } +    option "--fontdir=PATH",              ->(value) { Config.global.fontdir              = value } +    option "--servicedir=PATH",           ->(value) { Config.global.servicedir           = value } +    option "--input_methoddir=PATH",      ->(value) { Config.global.input_methoddir      = value } +    option "--internet_plugindir=PATH",   ->(value) { Config.global.internet_plugindir   = value } +    option "--audio_unit_plugindir=PATH", ->(value) { Config.global.audio_unit_plugindir = value } +    option "--vst_plugindir=PATH",        ->(value) { Config.global.vst_plugindir        = value } +    option "--vst3_plugindir=PATH",       ->(value) { Config.global.vst3_plugindir       = value } +    option "--screen_saverdir=PATH",      ->(value) { Config.global.screen_saverdir      = value }      option "--help", :help, false diff --git a/Library/Homebrew/cask/lib/hbc/config.rb b/Library/Homebrew/cask/lib/hbc/config.rb new file mode 100644 index 000000000..43408d53d --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/config.rb @@ -0,0 +1,65 @@ +module Hbc +  class Config +    def self.global +      @global ||= new +    end + +    attr_reader :binarydir + +    def initialize( +      appdir:               "/Applications", +      prefpanedir:          "~/Library/PreferencePanes", +      qlplugindir:          "~/Library/QuickLook", +      dictionarydir:        "~/Library/Dictionaries", +      fontdir:              "~/Library/Fonts", +      colorpickerdir:       "~/Library/ColorPickers", +      servicedir:           "~/Library/Services", +      input_methoddir:      "~/Library/Input Methods", +      internet_plugindir:   "~/Library/Internet Plug-Ins", +      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" +    ) + +      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" +    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 + +      define_method(:"#{dir}=") do |path| +        instance_variable_set(:"@#{dir}", Pathname(path).expand_path) +      end +    end +  end +end diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb index 22f0d2f66..9a88f1b62 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -292,11 +292,7 @@ module Hbc      end      def appdir -      self.class.appdir -    end - -    def self.appdir -      Hbc.appdir.sub(%r{\/$}, "") +      cask.config.appdir      end    end  end diff --git a/Library/Homebrew/cask/lib/hbc/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb index 5c9a28f5d..40ba2989f 100644 --- a/Library/Homebrew/cask/lib/hbc/locations.rb +++ b/Library/Homebrew/cask/lib/hbc/locations.rb @@ -15,88 +15,6 @@ module Hbc          @cache ||= HOMEBREW_CACHE.join("Cask")        end -      attr_writer :appdir - -      def appdir -        @appdir ||= Pathname.new("/Applications").expand_path -      end - -      attr_writer :prefpanedir - -      def prefpanedir -        @prefpanedir ||= Pathname.new("~/Library/PreferencePanes").expand_path -      end - -      attr_writer :qlplugindir - -      def qlplugindir -        @qlplugindir ||= Pathname.new("~/Library/QuickLook").expand_path -      end - -      attr_writer :dictionarydir - -      def dictionarydir -        @dictionarydir ||= Pathname.new("~/Library/Dictionaries").expand_path -      end - -      attr_writer :fontdir - -      def fontdir -        @fontdir ||= Pathname.new("~/Library/Fonts").expand_path -      end - -      attr_writer :colorpickerdir - -      def colorpickerdir -        @colorpickerdir ||= Pathname.new("~/Library/ColorPickers").expand_path -      end - -      attr_writer :servicedir - -      def servicedir -        @servicedir ||= Pathname.new("~/Library/Services").expand_path -      end - -      def binarydir -        @binarydir ||= HOMEBREW_PREFIX.join("bin") -      end - -      attr_writer :input_methoddir - -      def input_methoddir -        @input_methoddir ||= Pathname.new("~/Library/Input Methods").expand_path -      end - -      attr_writer :internet_plugindir - -      def internet_plugindir -        @internet_plugindir ||= Pathname.new("~/Library/Internet Plug-Ins").expand_path -      end - -      attr_writer :audio_unit_plugindir - -      def audio_unit_plugindir -        @audio_unit_plugindir ||= Pathname.new("~/Library/Audio/Plug-Ins/Components").expand_path -      end - -      attr_writer :vst_plugindir - -      def vst_plugindir -        @vst_plugindir ||= Pathname.new("~/Library/Audio/Plug-Ins/VST").expand_path -      end - -      attr_writer :vst3_plugindir - -      def vst3_plugindir -        @vst3_plugindir ||= Pathname.new("~/Library/Audio/Plug-Ins/VST3").expand_path -      end - -      attr_writer :screen_saverdir - -      def screen_saverdir -        @screen_saverdir ||= Pathname.new("~/Library/Screen Savers").expand_path -      end -        attr_writer :default_tap        def default_tap diff --git a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb index 847bf25fa..2168ac606 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 Hbc::Artifact::App, :cask do      }      let(:source_path) { cask.staged_path.join("Caffeine.app") } -    let(:target_path) { Hbc.appdir.join("AnotherName.app") } +    let(:target_path) { Hbc::Config.global.appdir.join("AnotherName.app") }      before do        InstallHelper.install_without_artifacts(cask) @@ -58,7 +58,7 @@ describe Hbc::Artifact::App, :cask do        expect(target_path).to be_a_directory        expect(source_path).not_to exist -      expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist +      expect(Hbc::Config.global.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 285cc4f31..97e19165b 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -5,7 +5,7 @@ describe Hbc::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) { Hbc.appdir.join("Caffeine.app") } +  let(:target_path) { Hbc::Config.global.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 Hbc::Artifact::App, :cask do        expect(target_path).to be_a_directory        expect(source_path).not_to exist -      expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist +      expect(Hbc::Config.global.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 e9514d9ae..d072060cc 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -5,7 +5,7 @@ describe Hbc::Artifact::Binary, :cask do      end    }    let(:artifacts) { cask.artifacts.select { |a| a.is_a?(described_class) } } -  let(:expected_path) { Hbc.binarydir.join("binary") } +  let(:expected_path) { Hbc::Config.global.binarydir.join("binary") }    after(:each) do      FileUtils.rm expected_path if expected_path.exist? @@ -38,7 +38,7 @@ describe Hbc::Artifact::Binary, :cask do        end      } -    let(:expected_path) { Hbc.binarydir.join("naked_non_executable") } +    let(:expected_path) { Hbc::Config.global.binarydir.join("naked_non_executable") }      it "makes the binary executable" do        expect(FileUtils).to receive(:chmod) @@ -76,7 +76,7 @@ describe Hbc::Artifact::Binary, :cask do    end    it "creates parent directory if it doesn't exist" do -    FileUtils.rmdir Hbc.binarydir +    FileUtils.rmdir Hbc::Config.global.binarydir      artifacts.each do |artifact|        artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) diff --git a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb index ea567abee..7e1285476 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 Hbc::Artifact::Artifact, :cask do    }    let(:source_path) { cask.staged_path.join("Caffeine.app") } -  let(:target_path) { Hbc.appdir.join("Caffeine.app") } +  let(:target_path) { Hbc::Config.global.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 80d3e917f..62a2fbfd7 100644 --- a/Library/Homebrew/test/cask/artifact/suite_spec.rb +++ b/Library/Homebrew/test/cask/artifact/suite_spec.rb @@ -9,7 +9,7 @@ describe Hbc::Artifact::Suite, :cask do      end    } -  let(:target_path) { Hbc.appdir.join("Caffeine") } +  let(:target_path) { Hbc::Config.global.appdir.join("Caffeine") }    let(:source_path) { cask.staged_path.join("Caffeine") }    before(:each) 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 8367dc27d..0d6f47d13 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 Hbc::Artifact::App, :cask do      }      let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") } -    let(:target_path_mini) { Hbc.appdir.join("Caffeine Mini.app") } +    let(:target_path_mini) { Hbc::Config.global.appdir.join("Caffeine Mini.app") }      let(:source_path_pro) { cask.staged_path.join("Caffeine Pro.app") } -    let(:target_path_pro) { Hbc.appdir.join("Caffeine Pro.app") } +    let(:target_path_pro) { Hbc::Config.global.appdir.join("Caffeine Pro.app") }      before(:each) do        InstallHelper.install_without_artifacts(cask) @@ -52,7 +52,7 @@ describe Hbc::Artifact::App, :cask do        expect(target_path_mini).to be_a_directory        expect(source_path_mini).not_to exist -      expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist +      expect(Hbc::Config.global.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/cli/install_spec.rb b/Library/Homebrew/test/cask/cli/install_spec.rb index 25d6cdc93..cc5450c79 100644 --- a/Library/Homebrew/test/cask/cli/install_spec.rb +++ b/Library/Homebrew/test/cask/cli/install_spec.rb @@ -23,9 +23,9 @@ describe Hbc::CLI::Install, :cask do      described_class.run("local-transmission", "local-caffeine")      expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed -    expect(Hbc.appdir.join("Transmission.app")).to be_a_directory +    expect(Hbc::Config.global.appdir.join("Transmission.app")).to be_a_directory      expect(Hbc::CaskLoader.load(cask_path("local-caffeine"))).to be_installed -    expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory +    expect(Hbc::Config.global.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/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index eef233acc..98eb6a8da 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -80,9 +80,9 @@ describe Hbc::CLI::List, :cask do          described_class.run("local-transmission", "local-caffeine")        }.to output(<<~EOS).to_stdout          ==> Apps -        #{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv}) +        #{Hbc::Config.global.appdir.join("Transmission.app")} (#{Hbc::Config.global.appdir.join("Transmission.app").abv})          ==> Apps -        Missing App: #{Hbc.appdir.join("Caffeine.app")} +        Missing App: #{Hbc::Config.global.appdir.join("Caffeine.app")}        EOS      end    end diff --git a/Library/Homebrew/test/cask/cli/options_spec.rb b/Library/Homebrew/test/cask/cli/options_spec.rb index 82d830795..8b084113c 100644 --- a/Library/Homebrew/test/cask/cli/options_spec.rb +++ b/Library/Homebrew/test/cask/cli/options_spec.rb @@ -1,106 +1,136 @@  describe Hbc::CLI, :cask do    it "supports setting the appdir" do +    allow(Hbc::Config.global).to receive(:appdir).and_call_original +      described_class.new.process_options("help", "--appdir=/some/path/foo") -    expect(Hbc.appdir).to eq(Pathname.new("/some/path/foo")) +    expect(Hbc::Config.global.appdir).to eq(Pathname.new("/some/path/foo"))    end    it "supports setting the appdir from ENV" do +    allow(Hbc::Config.global).to receive(:appdir).and_call_original +      ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar"      described_class.new.process_options("help") -    expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar")) +    expect(Hbc::Config.global.appdir).to eq(Pathname.new("/some/path/bar"))    end    it "supports setting the prefpanedir" do +    allow(Hbc::Config.global).to receive(:prefpanedir).and_call_original +      described_class.new.process_options("help", "--prefpanedir=/some/path/foo") -    expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/foo")) +    expect(Hbc::Config.global.prefpanedir).to eq(Pathname.new("/some/path/foo"))    end    it "supports setting the prefpanedir from ENV" do +    allow(Hbc::Config.global).to receive(:prefpanedir).and_call_original +      ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar"      described_class.new.process_options("help") -    expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar")) +    expect(Hbc::Config.global.prefpanedir).to eq(Pathname.new("/some/path/bar"))    end    it "supports setting the qlplugindir" do +    allow(Hbc::Config.global).to receive(:qlplugindir).and_call_original +      described_class.new.process_options("help", "--qlplugindir=/some/path/foo") -    expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/foo")) +    expect(Hbc::Config.global.qlplugindir).to eq(Pathname.new("/some/path/foo"))    end    it "supports setting the qlplugindir from ENV" do +    allow(Hbc::Config.global).to receive(:qlplugindir).and_call_original +      ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar"      described_class.new.process_options("help") -    expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar")) +    expect(Hbc::Config.global.qlplugindir).to eq(Pathname.new("/some/path/bar"))    end    it "supports setting the colorpickerdir" do +    allow(Hbc::Config.global).to receive(:colorpickerdir).and_call_original +      described_class.new.process_options("help", "--colorpickerdir=/some/path/foo") -    expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/foo")) +    expect(Hbc::Config.global.colorpickerdir).to eq(Pathname.new("/some/path/foo"))    end    it "supports setting the colorpickerdir from ENV" do +    allow(Hbc::Config.global).to receive(:colorpickerdir).and_call_original +      ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar"      described_class.new.process_options("help") -    expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar")) +    expect(Hbc::Config.global.colorpickerdir).to eq(Pathname.new("/some/path/bar"))    end    it "supports setting the dictionarydir" do +    allow(Hbc::Config.global).to receive(:dictionarydir).and_call_original +      described_class.new.process_options("help", "--dictionarydir=/some/path/foo") -    expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/foo")) +    expect(Hbc::Config.global.dictionarydir).to eq(Pathname.new("/some/path/foo"))    end    it "supports setting the dictionarydir from ENV" do +    allow(Hbc::Config.global).to receive(:dictionarydir).and_call_original +      ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar"      described_class.new.process_options("help") -    expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar")) +    expect(Hbc::Config.global.dictionarydir).to eq(Pathname.new("/some/path/bar"))    end    it "supports setting the fontdir" do +    allow(Hbc::Config.global).to receive(:fontdir).and_call_original +      described_class.new.process_options("help", "--fontdir=/some/path/foo") -    expect(Hbc.fontdir).to eq(Pathname.new("/some/path/foo")) +    expect(Hbc::Config.global.fontdir).to eq(Pathname.new("/some/path/foo"))    end    it "supports setting the fontdir from ENV" do +    allow(Hbc::Config.global).to receive(:fontdir).and_call_original +      ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar"      described_class.new.process_options("help") -    expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar")) +    expect(Hbc::Config.global.fontdir).to eq(Pathname.new("/some/path/bar"))    end    it "supports setting the servicedir" do +    allow(Hbc::Config.global).to receive(:servicedir).and_call_original +      described_class.new.process_options("help", "--servicedir=/some/path/foo") -    expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo")) +    expect(Hbc::Config.global.servicedir).to eq(Pathname.new("/some/path/foo"))    end    it "supports setting the servicedir from ENV" do +    allow(Hbc::Config.global).to receive(:servicedir).and_call_original +      ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar"      described_class.new.process_options("help") -    expect(Hbc.servicedir).to eq(Pathname.new("/some/path/bar")) +    expect(Hbc::Config.global.servicedir).to eq(Pathname.new("/some/path/bar"))    end    it "allows additional options to be passed through" do +    allow(Hbc::Config.global).to receive(:appdir).and_call_original +      rest = described_class.new.process_options("edit", "foo", "--create", "--appdir=/some/path/qux") -    expect(Hbc.appdir).to eq(Pathname.new("/some/path/qux")) +    expect(Hbc::Config.global.appdir).to eq(Pathname.new("/some/path/qux"))      expect(rest).to eq(%w[edit foo --create])    end diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb index 345e1b9f2..322394de4 100644 --- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb @@ -50,9 +50,9 @@ describe Hbc::CLI::Uninstall, :cask do      described_class.run("local-caffeine", "local-transmission")      expect(caffeine).not_to be_installed -    expect(Hbc.appdir.join("Transmission.app")).not_to exist +    expect(Hbc::Config.global.appdir.join("Transmission.app")).not_to exist      expect(transmission).not_to be_installed -    expect(Hbc.appdir.join("Caffeine.app")).not_to exist +    expect(Hbc::Config.global.appdir.join("Caffeine.app")).not_to exist    end    it "calls `uninstall` before removing artifacts" do @@ -61,14 +61,14 @@ describe Hbc::CLI::Uninstall, :cask do      Hbc::Installer.new(cask).install      expect(cask).to be_installed -    expect(Hbc.appdir.join("MyFancyApp.app")).to exist +    expect(Hbc::Config.global.appdir.join("MyFancyApp.app")).to exist      expect {        described_class.run("with-uninstall-script-app")      }.not_to raise_error      expect(cask).not_to be_installed -    expect(Hbc.appdir.join("MyFancyApp.app")).not_to exist +    expect(Hbc::Config.global.appdir.join("MyFancyApp.app")).not_to exist    end    it "can uninstall Casks when the uninstall script is missing, but only when using `--force`" do @@ -78,7 +78,7 @@ describe Hbc::CLI::Uninstall, :cask do      expect(cask).to be_installed -    Hbc.appdir.join("MyFancyApp.app").rmtree +    Hbc::Config.global.appdir.join("MyFancyApp.app").rmtree      expect { described_class.run("with-uninstall-script-app") }      .to raise_error(Hbc::CaskError, /uninstall script .* does not exist/) @@ -141,7 +141,7 @@ describe Hbc::CLI::Uninstall, :cask do    end    describe "when Casks in Taps have been renamed or removed" do -    let(:app) { Hbc.appdir.join("ive-been-renamed.app") } +    let(:app) { Hbc::Config.global.appdir.join("ive-been-renamed.app") }      let(:caskroom_path) { Hbc.caskroom.join("ive-been-renamed").tap(&:mkpath) }      let(:saved_caskfile) { caskroom_path.join(".metadata", "latest", "timestamp", "Casks").join("ive-been-renamed.rb") } diff --git a/Library/Homebrew/test/cask/cli/upgrade_spec.rb b/Library/Homebrew/test/cask/cli/upgrade_spec.rb index 49775156e..af026157e 100644 --- a/Library/Homebrew/test/cask/cli/upgrade_spec.rb +++ b/Library/Homebrew/test/cask/cli/upgrade_spec.rb @@ -22,9 +22,9 @@ describe Hbc::CLI::Upgrade, :cask do      describe 'without --greedy it ignores the Casks with "version latest" or "auto_updates true"' do        it "updates all the installed Casks when no token is provided" do          local_caffeine = Hbc::CaskLoader.load("local-caffeine") -        local_caffeine_path = Hbc.appdir.join("Caffeine.app") +        local_caffeine_path = Hbc::Config.global.appdir.join("Caffeine.app")          local_transmission = Hbc::CaskLoader.load("local-transmission") -        local_transmission_path = Hbc.appdir.join("Transmission.app") +        local_transmission_path = Hbc::Config.global.appdir.join("Transmission.app")          expect(local_caffeine).to be_installed          expect(local_caffeine_path).to be_a_directory @@ -47,9 +47,9 @@ describe Hbc::CLI::Upgrade, :cask do        it "updates only the Casks specified in the command line" do          local_caffeine = Hbc::CaskLoader.load("local-caffeine") -        local_caffeine_path = Hbc.appdir.join("Caffeine.app") +        local_caffeine_path = Hbc::Config.global.appdir.join("Caffeine.app")          local_transmission = Hbc::CaskLoader.load("local-transmission") -        local_transmission_path = Hbc.appdir.join("Transmission.app") +        local_transmission_path = Hbc::Config.global.appdir.join("Transmission.app")          expect(local_caffeine).to be_installed          expect(local_caffeine_path).to be_a_directory @@ -72,9 +72,9 @@ describe Hbc::CLI::Upgrade, :cask do        it 'updates "auto_updates" and "latest" Casks when their tokens are provided in the command line' do          local_caffeine = Hbc::CaskLoader.load("local-caffeine") -        local_caffeine_path = Hbc.appdir.join("Caffeine.app") +        local_caffeine_path = Hbc::Config.global.appdir.join("Caffeine.app")          auto_updates = Hbc::CaskLoader.load("auto-updates") -        auto_updates_path = Hbc.appdir.join("MyFancyApp.app") +        auto_updates_path = Hbc::Config.global.appdir.join("MyFancyApp.app")          expect(local_caffeine).to be_installed          expect(local_caffeine_path).to be_a_directory @@ -99,14 +99,14 @@ describe Hbc::CLI::Upgrade, :cask do      describe "with --greedy it checks additional Casks" do        it 'includes the Casks with "auto_updates true" or "version latest"' do          local_caffeine = Hbc::CaskLoader.load("local-caffeine") -        local_caffeine_path = Hbc.appdir.join("Caffeine.app") +        local_caffeine_path = Hbc::Config.global.appdir.join("Caffeine.app")          auto_updates = Hbc::CaskLoader.load("auto-updates") -        auto_updates_path = Hbc.appdir.join("MyFancyApp.app") +        auto_updates_path = Hbc::Config.global.appdir.join("MyFancyApp.app")          local_transmission = Hbc::CaskLoader.load("local-transmission") -        local_transmission_path = Hbc.appdir.join("Transmission.app") +        local_transmission_path = Hbc::Config.global.appdir.join("Transmission.app")          version_latest = Hbc::CaskLoader.load("version-latest") -        version_latest_path_1 = Hbc.appdir.join("Caffeine Mini.app") -        version_latest_path_2 = Hbc.appdir.join("Caffeine Pro.app") +        version_latest_path_1 = Hbc::Config.global.appdir.join("Caffeine Mini.app") +        version_latest_path_2 = Hbc::Config.global.appdir.join("Caffeine Pro.app")          expect(local_caffeine).to be_installed          expect(local_caffeine_path).to be_a_directory @@ -147,7 +147,7 @@ describe Hbc::CLI::Upgrade, :cask do        it 'does not include the Casks with "auto_updates true" when the version did not change' do          cask = Hbc::CaskLoader.load("auto-updates") -        cask_path = Hbc.appdir.join("MyFancyApp.app") +        cask_path = Hbc::Config.global.appdir.join("MyFancyApp.app")          expect(cask).to be_installed          expect(cask_path).to be_a_directory @@ -188,7 +188,7 @@ describe Hbc::CLI::Upgrade, :cask do      it "restores the old Cask if the upgrade failed" do        will_fail_if_upgraded = Hbc::CaskLoader.load("will-fail-if-upgraded") -      will_fail_if_upgraded_path = Hbc.appdir.join("container") +      will_fail_if_upgraded_path = Hbc::Config.global.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 Hbc::CLI::Upgrade, :cask do      it "does not restore the old Cask if the upgrade failed pre-install" do        bad_checksum = Hbc::CaskLoader.load("bad-checksum") -      bad_checksum_path = Hbc.appdir.join("Caffeine.app") +      bad_checksum_path = Hbc::Config.global.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/cli/zap_spec.rb b/Library/Homebrew/test/cask/cli/zap_spec.rb index 05c882854..e85120f5f 100644 --- a/Library/Homebrew/test/cask/cli/zap_spec.rb +++ b/Library/Homebrew/test/cask/cli/zap_spec.rb @@ -23,9 +23,9 @@ describe Hbc::CLI::Zap, :cask do      described_class.run("local-caffeine", "local-transmission")      expect(caffeine).not_to be_installed -    expect(Hbc.appdir.join("Caffeine.app")).not_to be_a_symlink +    expect(Hbc::Config.global.appdir.join("Caffeine.app")).not_to be_a_symlink      expect(transmission).not_to be_installed -    expect(Hbc.appdir.join("Transmission.app")).not_to be_a_symlink +    expect(Hbc::Config.global.appdir.join("Transmission.app")).not_to be_a_symlink    end    # TODO: Explicit test that both zap and uninstall directives get dispatched. diff --git a/Library/Homebrew/test/cask/cli_spec.rb b/Library/Homebrew/test/cask/cli_spec.rb index f88af4188..e88b24ba2 100644 --- a/Library/Homebrew/test/cask/cli_spec.rb +++ b/Library/Homebrew/test/cask/cli_spec.rb @@ -57,10 +57,13 @@ describe Hbc::CLI, :cask do      end      it "respects the env variable when choosing what appdir to create" do -      allow(ENV).to receive(:[]) +      allow(ENV).to receive(:[]).and_call_original        allow(ENV).to receive(:[]).with("HOMEBREW_CASK_OPTS").and_return("--appdir=/custom/appdir") -      expect(Hbc).to receive(:appdir=).with(Pathname.new("/custom/appdir")) +      allow(Hbc::Config.global).to receive(:appdir).and_call_original +        described_class.run("noop") + +      expect(Hbc::Config.global.appdir).to eq(Pathname.new("/custom/appdir"))      end      it "exits with a status of 1 when something goes wrong" do diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index cd296b5ab..d3bb46264 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -551,14 +551,14 @@ describe Hbc::DSL, :cask do        let(:token) { "appdir-interpolation" }        it "is allowed" do -        expect(cask.artifacts.first.source).to eq(Hbc.appdir/"some/path") +        expect(cask.artifacts.first.source).to eq(Hbc::Config.global.appdir/"some/path")        end      end      it "does not include a trailing slash" do        begin -        original_appdir = Hbc.appdir -        Hbc.appdir = "#{original_appdir}/" +        original_appdir = Hbc::Config.global.appdir +        Hbc::Config.global.appdir = "#{original_appdir}/"          cask = Hbc::Cask.new("appdir-trailing-slash") do            binary "#{appdir}/some/path" @@ -566,7 +566,7 @@ describe Hbc::DSL, :cask do          expect(cask.artifacts.first.source).to eq(original_appdir/"some/path")        ensure -        Hbc.appdir = original_appdir +        Hbc::Config.global.appdir = original_appdir        end      end    end diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index 2dc27f04c..5fc730b33 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -10,7 +10,7 @@ describe Hbc::Installer, :cask do        Hbc::Installer.new(caffeine).install        expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).to be_a_directory -      expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory +      expect(Hbc::Config.global.appdir.join("Caffeine.app")).to be_a_directory      end      it "works with dmg-based Casks" do @@ -19,7 +19,7 @@ describe Hbc::Installer, :cask do        Hbc::Installer.new(asset).install        expect(Hbc.caskroom.join("container-dmg", asset.version)).to be_a_directory -      expect(Hbc.appdir.join("container")).to be_a_file +      expect(Hbc::Config.global.appdir.join("container")).to be_a_file      end      it "works with tar-gz-based Casks" do @@ -28,7 +28,7 @@ describe Hbc::Installer, :cask do        Hbc::Installer.new(asset).install        expect(Hbc.caskroom.join("container-tar-gz", asset.version)).to be_a_directory -      expect(Hbc.appdir.join("container")).to be_a_file +      expect(Hbc::Config.global.appdir.join("container")).to be_a_file      end      it "works with xar-based Casks" do @@ -37,7 +37,7 @@ describe Hbc::Installer, :cask do        Hbc::Installer.new(asset).install        expect(Hbc.caskroom.join("container-xar", asset.version)).to be_a_directory -      expect(Hbc.appdir.join("container")).to be_a_file +      expect(Hbc::Config.global.appdir.join("container")).to be_a_file      end      it "works with pure bzip2-based Casks" do @@ -46,7 +46,7 @@ describe Hbc::Installer, :cask do        Hbc::Installer.new(asset).install        expect(Hbc.caskroom.join("container-bzip2", asset.version)).to be_a_directory -      expect(Hbc.appdir.join("container-bzip2--#{asset.version}")).to be_a_file +      expect(Hbc::Config.global.appdir.join("container-bzip2--#{asset.version}")).to be_a_file      end      it "works with pure gzip-based Casks" do @@ -55,7 +55,7 @@ describe Hbc::Installer, :cask do        Hbc::Installer.new(asset).install        expect(Hbc.caskroom.join("container-gzip", asset.version)).to be_a_directory -      expect(Hbc.appdir.join("container")).to be_a_file +      expect(Hbc::Config.global.appdir.join("container")).to be_a_file      end      it "blows up on a bad checksum" do @@ -183,7 +183,7 @@ describe Hbc::Installer, :cask do        Hbc::Installer.new(nested_app).install -      expect(Hbc.appdir.join("MyNestedApp.app")).to be_a_directory +      expect(Hbc::Config.global.appdir.join("MyNestedApp.app")).to be_a_directory      end      it "generates and finds a timestamped metadata directory for an installed Cask" do diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-absolute-target.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-absolute-target.rb index a1844a9c9..dc73ab773 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-absolute-target.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-absolute-target.rb @@ -1,3 +1,3 @@  cask 'generic-artifact-absolute-target' do -  artifact 'Caffeine.app', target: "#{Hbc.appdir}/Caffeine.app" +  artifact 'Caffeine.app', target: "#{Hbc::Config.global.appdir}/Caffeine.app"  end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact.rb index d6ce0ce8d..40c0da95a 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact.rb @@ -5,5 +5,5 @@ cask 'with-generic-artifact' do    url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"    homepage 'http://example.com/with-generic-artifact' -  artifact 'Caffeine.app', target: "#{Hbc.appdir}/Caffeine.app" +  artifact 'Caffeine.app', target: "#{Hbc::Config.global.appdir}/Caffeine.app"  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 e1afc44bf..46303a46e 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 @@ -6,25 +6,26 @@ require "test/support/helper/cask/fake_system_command"  require "test/support/helper/cask/install_helper"  require "test/support/helper/cask/never_sudo_system_command" -HOMEBREW_CASK_DIRS = [ -  :appdir, -  :prefpanedir, -  :qlplugindir, -  :servicedir, -].freeze +HOMEBREW_CASK_DIRS = { +  :appdir      => Pathname.new(TEST_TMPDIR).join("cask-appdir"), +  :prefpanedir => Pathname.new(TEST_TMPDIR).join("cask-prefpanedir"), +  :qlplugindir => Pathname.new(TEST_TMPDIR).join("cask-qlplugindir"), +  :servicedir  => Pathname.new(TEST_TMPDIR).join("cask-servicedir"), +}.freeze  RSpec.shared_context "Homebrew-Cask" do +  before(:each) do +    HOMEBREW_CASK_DIRS.each do |method, path| +      allow(Hbc::Config.global).to receive(method).and_return(path) +    end +  end +    around(:each) do |example|      third_party_tap = Tap.fetch("third-party", "tap")      begin -      [Hbc.binarydir, Hbc.caskroom, Hbc.cache].each(&:mkpath) +      HOMEBREW_CASK_DIRS.values.each(&:mkpath) -      dirs = HOMEBREW_CASK_DIRS.map do |dir| -        Pathname.new(TEST_TMPDIR).join("cask-#{dir}").tap do |path| -          path.mkpath -          Hbc.public_send("#{dir}=", path) -        end -      end +      [Hbc::Config.global.binarydir, Hbc.caskroom, Hbc.cache].each(&:mkpath)        Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|          FileUtils.mkdir_p tap.path.dirname @@ -38,8 +39,8 @@ RSpec.shared_context "Homebrew-Cask" do        example.run      ensure -      FileUtils.rm_rf dirs -      FileUtils.rm_rf [Hbc.binarydir, Hbc.caskroom, Hbc.cache] +      FileUtils.rm_rf HOMEBREW_CASK_DIRS.values +      FileUtils.rm_rf [Hbc::Config.global.binarydir, Hbc.caskroom, Hbc.cache]        Hbc.default_tap.path.unlink        FileUtils.rm_rf Hbc.default_tap.path.parent        third_party_tap.path.unlink diff --git a/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb b/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb index 361179b9e..e7fa172c4 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb @@ -22,7 +22,7 @@ shared_examples Hbc::Staged do    end    it "can get the Info.plist file for the primary app" do -    expect(staged.info_plist_file).to eq Hbc.appdir.join("TestCask.app/Contents/Info.plist") +    expect(staged.info_plist_file).to eq Hbc::Config.global.appdir.join("TestCask.app/Contents/Info.plist")    end    it "can execute commands on the Info.plist file" do | 
