Create Hbc::Config class.
This commit is contained in:
parent
d558ec0933
commit
6760d26319
@ -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"
|
||||
|
||||
@ -19,7 +19,7 @@ module Hbc
|
||||
end
|
||||
|
||||
def self.resolve_target(target)
|
||||
Hbc.public_send(dirmethod).join(target)
|
||||
Config.global.public_send(dirmethod).join(target)
|
||||
end
|
||||
|
||||
attr_reader :source, :target
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
65
Library/Homebrew/cask/lib/hbc/config.rb
Normal file
65
Library/Homebrew/cask/lib/hbc/config.rb
Normal file
@ -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
|
||||
@ -292,11 +292,7 @@ module Hbc
|
||||
end
|
||||
|
||||
def appdir
|
||||
self.class.appdir
|
||||
end
|
||||
|
||||
def self.appdir
|
||||
Hbc.appdir.sub(%r{\/$}, "")
|
||||
Config.global.appdir
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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") }
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user