Merge pull request #4314 from reitermarkus/remove-locations

Remove `Locations` module.
This commit is contained in:
Markus Reiter 2018-06-09 10:41:08 +02:00 committed by GitHub
commit 9ebcef785e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 114 additions and 131 deletions

View File

@ -15,7 +15,6 @@ require "hbc/download"
require "hbc/download_strategy" require "hbc/download_strategy"
require "hbc/exceptions" require "hbc/exceptions"
require "hbc/installer" require "hbc/installer"
require "hbc/locations"
require "hbc/config" require "hbc/config"
require "hbc/macos" require "hbc/macos"
require "hbc/pkg" require "hbc/pkg"
@ -28,8 +27,6 @@ require "hbc/verify"
require "hbc/version" require "hbc/version"
module Hbc module Hbc
include Locations
def self.init def self.init
Cache.ensure_cache_exists Cache.ensure_cache_exists
Caskroom.ensure_caskroom_exists Caskroom.ensure_caskroom_exists

View File

@ -2,11 +2,15 @@ module Hbc
module Cache module Cache
module_function module_function
def ensure_cache_exists def path
return if Hbc.cache.exist? @path ||= HOMEBREW_CACHE.join("Cask")
end
odebug "Creating Cache at #{Hbc.cache}" def ensure_cache_exists
Hbc.cache.mkpath return if path.exist?
odebug "Creating Cache at #{path}"
path.mkpath
end end
end end
end end

View File

@ -55,7 +55,7 @@ module Hbc
end end
def full_name def full_name
return token if tap == Hbc.default_tap return token if tap == Tap.default_cask_tap
qualified_token qualified_token
end end

View File

@ -78,7 +78,7 @@ module Hbc
def initialize(url) def initialize(url)
@url = URI(url) @url = URI(url)
super Hbc.cache/File.basename(@url.path) super Cache.path/File.basename(@url.path)
end end
def load def load
@ -207,7 +207,7 @@ module Hbc
end end
def self.default_path(token) def self.default_path(token)
Hbc.default_tap.cask_dir/"#{token.to_s.downcase}.rb" Tap.default_cask_tap.cask_dir/"#{token.to_s.downcase}.rb"
end end
def self.tap_paths(token) def self.tap_paths(token)

View File

@ -2,22 +2,26 @@ module Hbc
module Caskroom module Caskroom
module_function module_function
def ensure_caskroom_exists def path
return if Hbc.caskroom.exist? @path ||= HOMEBREW_PREFIX.join("Caskroom")
end
ohai "Creating Caskroom at #{Hbc.caskroom}" if $stdout.tty? def ensure_caskroom_exists
sudo = !Hbc.caskroom.parent.writable? return if path.exist?
ohai "Creating Caskroom at #{path}" if $stdout.tty?
sudo = !path.parent.writable?
ohai "We'll set permissions properly so we won't need sudo in the future" if $stdout.tty? && sudo ohai "We'll set permissions properly so we won't need sudo in the future" if $stdout.tty? && sudo
SystemCommand.run("/bin/mkdir", args: ["-p", Hbc.caskroom], sudo: sudo) SystemCommand.run("/bin/mkdir", args: ["-p", path], sudo: sudo)
SystemCommand.run("/bin/chmod", args: ["g+rwx", Hbc.caskroom], sudo: sudo) SystemCommand.run("/bin/chmod", args: ["g+rwx", path], sudo: sudo)
SystemCommand.run("/usr/sbin/chown", args: [Utils.current_user, Hbc.caskroom], sudo: sudo) SystemCommand.run("/usr/sbin/chown", args: [Utils.current_user, path], sudo: sudo)
SystemCommand.run("/usr/bin/chgrp", args: ["admin", Hbc.caskroom], sudo: sudo) SystemCommand.run("/usr/bin/chgrp", args: ["admin", path], sudo: sudo)
end end
def casks def casks
Pathname.glob(Hbc.caskroom.join("*")).sort.select(&:directory?).map do |path| Pathname.glob(path.join("*")).sort.select(&:directory?).map do |path|
token = path.basename.to_s token = path.basename.to_s
if tap_path = CaskLoader.tap_paths(token).first if tap_path = CaskLoader.tap_paths(token).first

View File

@ -163,7 +163,7 @@ module Hbc
MacOS.full_version = ENV["MACOS_VERSION"] unless ENV["MACOS_VERSION"].nil? MacOS.full_version = ENV["MACOS_VERSION"] unless ENV["MACOS_VERSION"].nil?
Hbc.default_tap.install unless Hbc.default_tap.installed? Tap.default_cask_tap.install unless Tap.default_cask_tap.installed?
Hbc.init if self.class.should_init?(command) Hbc.init if self.class.should_init?(command)
self.class.run_command(command, *args) self.class.run_command(command, *args)
rescue CaskError, ArgumentError, OptionParser::InvalidOption => e rescue CaskError, ArgumentError, OptionParser::InvalidOption => e

View File

@ -14,7 +14,7 @@ module Hbc
attr_reader :cache_location attr_reader :cache_location
def initialize(*args, cache_location: Hbc.cache) def initialize(*args, cache_location: Cache.path)
super(*args) super(*args)
@cache_location = Pathname.new(cache_location) @cache_location = Pathname.new(cache_location)
end end

View File

@ -60,7 +60,7 @@ module Hbc
def check_staging_location def check_staging_location
ohai "Homebrew-Cask Staging Location" ohai "Homebrew-Cask Staging Location"
path = Pathname.new(user_tilde(Hbc.caskroom.to_s)) path = Pathname.new(user_tilde(Caskroom.path.to_s))
if !path.exist? if !path.exist?
add_error "The staging path #{path} does not exist." add_error "The staging path #{path} does not exist."
@ -77,19 +77,17 @@ module Hbc
cleanup = CLI::Cleanup.new cleanup = CLI::Cleanup.new
count = cleanup.cache_files.count count = cleanup.cache_files.count
size = cleanup.disk_cleanup_size size = cleanup.disk_cleanup_size
msg = user_tilde(Hbc.cache.to_s) msg = user_tilde(Cache.path.to_s)
msg << " (#{number_readable(count)} files, #{disk_usage_readable(size)})" unless count.zero? msg << " (#{number_readable(count)} files, #{disk_usage_readable(size)})" unless count.zero?
puts msg puts msg
end end
def check_taps def check_taps
default_tap = Tap.default_cask_tap
alt_taps = Tap.select { |t| t.cask_dir.exist? && t != default_tap }
ohai "Homebrew-Cask Taps:" ohai "Homebrew-Cask Taps:"
[default_tap, *alt_taps].each do |tap|
default_tap = [Hbc.default_tap]
alt_taps = Tap.select { |t| t.cask_dir.exist? && t != Hbc.default_tap }
(default_tap + alt_taps).each do |tap|
if tap.path.nil? || tap.path.to_s.empty? if tap.path.nil? || tap.path.to_s.empty?
puts none_string puts none_string
else else
@ -175,7 +173,7 @@ module Hbc
end end
def self.alt_taps def self.alt_taps
Tap.select { |t| t.cask_dir.exist? && t != Hbc.default_tap } Tap.select { |t| t.cask_dir.exist? && t != Tap.default_cask_tap }
end end
def self.cask_count_for_tap(tap) def self.cask_count_for_tap(tap)
@ -240,7 +238,7 @@ module Hbc
cleanup = CLI::Cleanup.new cleanup = CLI::Cleanup.new
count = cleanup.cache_files.count count = cleanup.cache_files.count
size = cleanup.disk_cleanup_size size = cleanup.disk_cleanup_size
msg = user_tilde(Hbc.cache.to_s) msg = user_tilde(Cache.path.to_s)
msg << " (#{number_readable(count)} files, #{disk_usage_readable(size)})" unless count.zero? msg << " (#{number_readable(count)} files, #{disk_usage_readable(size)})" unless count.zero?
msg msg
end end

View File

@ -36,7 +36,7 @@ module Hbc
def initialize(*args, **options) def initialize(*args, **options)
super(*args, **options) super(*args, **options)
@ref_type, @ref = extract_ref @ref_type, @ref = extract_ref
@clone = Hbc.cache.join(cache_filename) @clone = Cache.path.join(cache_filename)
end end
def extract_ref def extract_ref
@ -65,7 +65,7 @@ module Hbc
class CurlDownloadStrategy < AbstractDownloadStrategy class CurlDownloadStrategy < AbstractDownloadStrategy
def tarball_path def tarball_path
@tarball_path ||= Hbc.cache.join("#{name}--#{version}#{ext}") @tarball_path ||= Cache.path.join("#{name}--#{version}#{ext}")
end end
def temporary_path def temporary_path

View File

@ -220,7 +220,7 @@ module Hbc
end end
def caskroom_path def caskroom_path
@caskroom_path ||= Hbc.caskroom.join(token) @caskroom_path ||= Caskroom.path.join(token)
end end
def staged_path def staged_path

View File

@ -292,19 +292,19 @@ module Hbc
ohai "Enabling accessibility access" ohai "Enabling accessibility access"
if MacOS.version <= :mountain_lion if MacOS.version <= :mountain_lion
@command.run!("/usr/bin/touch", @command.run!("/usr/bin/touch",
args: [Hbc.pre_mavericks_accessibility_dotfile], args: [MacOS.pre_mavericks_accessibility_dotfile],
sudo: true) sudo: true)
elsif MacOS.version <= :yosemite elsif MacOS.version <= :yosemite
@command.run!("/usr/bin/sqlite3", @command.run!("/usr/bin/sqlite3",
args: [ args: [
Hbc.tcc_db, MacOS.tcc_db,
"INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL);", "INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL);",
], ],
sudo: true) sudo: true)
elsif MacOS.version <= :el_capitan elsif MacOS.version <= :el_capitan
@command.run!("/usr/bin/sqlite3", @command.run!("/usr/bin/sqlite3",
args: [ args: [
Hbc.tcc_db, MacOS.tcc_db,
"INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL,NULL);", "INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL,NULL);",
], ],
sudo: true) sudo: true)
@ -325,7 +325,7 @@ module Hbc
ohai "Disabling accessibility access" ohai "Disabling accessibility access"
@command.run!("/usr/bin/sqlite3", @command.run!("/usr/bin/sqlite3",
args: [ args: [
Hbc.tcc_db, MacOS.tcc_db,
"DELETE FROM access WHERE client='#{bundle_identifier}';", "DELETE FROM access WHERE client='#{bundle_identifier}';",
], ],
sudo: true) sudo: true)

View File

@ -1,32 +0,0 @@
module Hbc
module Locations
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def caskroom
@caskroom ||= HOMEBREW_PREFIX.join("Caskroom")
end
def cache
@cache ||= HOMEBREW_CACHE.join("Cask")
end
attr_writer :default_tap
def default_tap
@default_tap ||= Tap.fetch("homebrew", "homebrew-cask")
end
def tcc_db
@tcc_db ||= Pathname.new("/Library/Application Support/com.apple.TCC/TCC.db")
end
def pre_mavericks_accessibility_dotfile
@pre_mavericks_accessibility_dotfile ||= Pathname.new("/private/var/db/.AccessibilityAPIEnabled")
end
end
end
end

View File

@ -3,7 +3,7 @@ module Hbc
@full_version ||= begin @full_version ||= begin
<<~EOS <<~EOS
Homebrew-Cask #{HOMEBREW_VERSION} Homebrew-Cask #{HOMEBREW_VERSION}
#{Hbc.default_tap.full_name} #{Hbc.default_tap.version_string} #{Tap.default_cask_tap.full_name} #{Tap.default_cask_tap.version_string}
EOS EOS
end end
end end

View File

@ -3,42 +3,42 @@ module Hbc
class << self class << self
module Compat module Compat
def migrate_legacy_caskroom def migrate_legacy_caskroom
return if Hbc.caskroom.exist? return if path.exist?
legacy_caskroom = Pathname.new("/opt/homebrew-cask/Caskroom") legacy_caskroom_path = Pathname.new("/opt/homebrew-cask/Caskroom")
return if Hbc.caskroom == legacy_caskroom return if path == legacy_caskroom_path
return unless legacy_caskroom.exist? return unless legacy_caskroom_path.exist?
return if legacy_caskroom.symlink? return if legacy_caskroom_path.symlink?
ohai "Migrating Caskroom from #{legacy_caskroom} to #{Hbc.caskroom}." ohai "Migrating Caskroom from #{legacy_caskroom_path} to #{path}."
if Hbc.caskroom.parent.writable? if path.parent.writable?
FileUtils.mv legacy_caskroom, Hbc.caskroom FileUtils.mv legacy_caskroom_path, path
else else
opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom." opoo "#{path.parent} is not writable, sudo is needed to move the Caskroom."
SystemCommand.run("/bin/mv", args: [legacy_caskroom, Hbc.caskroom.parent], sudo: true) SystemCommand.run("/bin/mv", args: [legacy_caskroom_path, path.parent], sudo: true)
end end
ohai "Creating symlink from #{Hbc.caskroom} to #{legacy_caskroom}." ohai "Creating symlink from #{path} to #{legacy_caskroom_path}."
if legacy_caskroom.parent.writable? if legacy_caskroom_path.parent.writable?
FileUtils.ln_s Hbc.caskroom, legacy_caskroom FileUtils.ln_s path, legacy_caskroom_path
else else
opoo "#{legacy_caskroom.parent} is not writable, sudo is needed to link the Caskroom." opoo "#{legacy_caskroom_path.parent} is not writable, sudo is needed to link the Caskroom."
SystemCommand.run("/bin/ln", args: ["-s", Hbc.caskroom, legacy_caskroom], sudo: true) SystemCommand.run("/bin/ln", args: ["-s", path, legacy_caskroom_path], sudo: true)
end end
end end
def migrate_caskroom_from_repo_to_prefix def migrate_caskroom_from_repo_to_prefix
repo_caskroom = HOMEBREW_REPOSITORY.join("Caskroom") repo_caskroom_path = HOMEBREW_REPOSITORY.join("Caskroom")
return if Hbc.caskroom.exist? return if path.exist?
return unless repo_caskroom.directory? return unless repo_caskroom_path.directory?
ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX" ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX"
if Hbc.caskroom.parent.writable? if path.parent.writable?
FileUtils.mv repo_caskroom, Hbc.caskroom FileUtils.mv repo_caskroom_path, path
else else
opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom." opoo "#{path.parent} is not writable, sudo is needed to move the Caskroom."
SystemCommand.run("/bin/mv", args: [repo_caskroom, Hbc.caskroom.parent], sudo: true) SystemCommand.run("/bin/mv", args: [repo_caskroom_path, path.parent], sudo: true)
end end
end end
end end

View File

@ -255,5 +255,13 @@ module OS
def mdfind_query(*ids) def mdfind_query(*ids)
ids.map! { |id| "kMDItemCFBundleIdentifier == #{id}" }.join(" || ") ids.map! { |id| "kMDItemCFBundleIdentifier == #{id}" }.join(" || ")
end end
def tcc_db
@tcc_db ||= Pathname.new("/Library/Application Support/com.apple.TCC/TCC.db")
end
def pre_mavericks_accessibility_dotfile
@pre_mavericks_accessibility_dotfile ||= Pathname.new("/private/var/db/.AccessibilityAPIEnabled")
end
end end
end end

View File

@ -46,6 +46,10 @@ class Tap
nil nil
end end
def self.default_cask_tap
@default_cask_tap ||= fetch("Homebrew", "cask")
end
extend Enumerable extend Enumerable
# The user name of this {Tap}. Usually, it's the Github username of # The user name of this {Tap}. Usually, it's the Github username of

View File

@ -16,7 +16,7 @@ describe "Accessibility Access", :cask do
it "can enable accessibility access in macOS releases prior to Mavericks" do it "can enable accessibility access in macOS releases prior to Mavericks" do
expect(fake_system_command).to receive(:run!).with( expect(fake_system_command).to receive(:run!).with(
"/usr/bin/touch", "/usr/bin/touch",
args: [Hbc.pre_mavericks_accessibility_dotfile], args: [MacOS.pre_mavericks_accessibility_dotfile],
sudo: true, sudo: true,
) )
@ -36,7 +36,7 @@ describe "Accessibility Access", :cask do
it "can enable accessibility access" do it "can enable accessibility access" do
expect(fake_system_command).to receive(:run!).with( expect(fake_system_command).to receive(:run!).with(
"/usr/bin/sqlite3", "/usr/bin/sqlite3",
args: [Hbc.tcc_db, "INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);"], args: [MacOS.tcc_db, "INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);"],
sudo: true, sudo: true,
) )
@ -46,7 +46,7 @@ describe "Accessibility Access", :cask do
it "can disable accessibility access" do it "can disable accessibility access" do
expect(fake_system_command).to receive(:run!).with( expect(fake_system_command).to receive(:run!).with(
"/usr/bin/sqlite3", "/usr/bin/sqlite3",
args: [Hbc.tcc_db, "DELETE FROM access WHERE client='com.example.BasicCask';"], args: [MacOS.tcc_db, "DELETE FROM access WHERE client='com.example.BasicCask';"],
sudo: true, sudo: true,
) )

View File

@ -22,7 +22,7 @@ describe Hbc::Cask, :cask do
end end
describe "load" do describe "load" do
let(:tap_path) { Hbc.default_tap.path } let(:tap_path) { Tap.default_cask_tap.path }
let(:file_dirname) { Pathname.new(__FILE__).dirname } let(:file_dirname) { Pathname.new(__FILE__).dirname }
let(:relative_tap_path) { tap_path.relative_path_from(file_dirname) } let(:relative_tap_path) { tap_path.relative_path_from(file_dirname) }
@ -74,7 +74,7 @@ describe Hbc::Cask, :cask do
it "proposes a versioned metadata directory name for each instance" do it "proposes a versioned metadata directory name for each instance" do
cask_token = "local-caffeine" cask_token = "local-caffeine"
c = Hbc::CaskLoader.load(cask_token) c = Hbc::CaskLoader.load(cask_token)
metadata_timestamped_path = Hbc.caskroom.join(cask_token, ".metadata", c.version) metadata_timestamped_path = Hbc::Caskroom.path.join(cask_token, ".metadata", c.version)
expect(c.metadata_versioned_path.to_s).to eq(metadata_timestamped_path.to_s) expect(c.metadata_versioned_path.to_s).to eq(metadata_timestamped_path.to_s)
end end
end end

View File

@ -12,7 +12,7 @@ describe Hbc::CLI::Info, :cask do
local-caffeine: 1.2.3 local-caffeine: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
Not installed Not installed
From: https://github.com/Homebrew/homebrew-cask-spec/blob/master/Casks/local-caffeine.rb From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/local-caffeine.rb
==> Name ==> Name
None None
==> Artifacts ==> Artifacts
@ -26,7 +26,7 @@ describe Hbc::CLI::Info, :cask do
local-caffeine: 1.2.3 local-caffeine: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
Not installed Not installed
From: https://github.com/Homebrew/homebrew-cask-spec/blob/master/Casks/local-caffeine.rb From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/local-caffeine.rb
==> Name ==> Name
None None
==> Artifacts ==> Artifacts
@ -34,7 +34,7 @@ describe Hbc::CLI::Info, :cask do
local-transmission: 2.61 local-transmission: 2.61
http://example.com/local-transmission http://example.com/local-transmission
Not installed Not installed
From: https://github.com/Homebrew/homebrew-cask-spec/blob/master/Casks/local-transmission.rb From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/local-transmission.rb
==> Name ==> Name
None None
==> Artifacts ==> Artifacts
@ -56,7 +56,7 @@ describe Hbc::CLI::Info, :cask do
with-caveats: 1.2.3 with-caveats: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
Not installed Not installed
From: https://github.com/Homebrew/homebrew-cask-spec/blob/master/Casks/with-caveats.rb From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/with-caveats.rb
==> Name ==> Name
None None
==> Artifacts ==> Artifacts
@ -82,7 +82,7 @@ describe Hbc::CLI::Info, :cask do
with-conditional-caveats: 1.2.3 with-conditional-caveats: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
Not installed Not installed
From: https://github.com/Homebrew/homebrew-cask-spec/blob/master/Casks/with-conditional-caveats.rb From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/with-conditional-caveats.rb
==> Name ==> Name
None None
==> Artifacts ==> Artifacts
@ -97,7 +97,7 @@ describe Hbc::CLI::Info, :cask do
with-languages: 1.2.3 with-languages: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
Not installed Not installed
From: https://github.com/Homebrew/homebrew-cask-spec/blob/master/Casks/with-languages.rb From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/with-languages.rb
==> Name ==> Name
None None
==> Languages ==> Languages
@ -114,7 +114,7 @@ describe Hbc::CLI::Info, :cask do
without-languages: 1.2.3 without-languages: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
Not installed Not installed
From: https://github.com/Homebrew/homebrew-cask-spec/blob/master/Casks/without-languages.rb From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/without-languages.rb
==> Name ==> Name
None None
==> Artifacts ==> Artifacts

View File

@ -89,7 +89,7 @@ describe Hbc::CLI::Style, :cask do
end end
end end
it { is_expected.to contain_exactly(a_path_ending_with("/homebrew/homebrew-cask-spec/Casks"), a_path_ending_with("/third-party/homebrew-tap/Casks")) } it { is_expected.to contain_exactly(a_path_ending_with("/homebrew/homebrew-cask/Casks"), a_path_ending_with("/third-party/homebrew-tap/Casks")) }
end end
context "when at least one cask token is a path that exists" do context "when at least one cask token is a path that exists" do

View File

@ -103,7 +103,7 @@ describe Hbc::CLI::Uninstall, :cask do
[last_installed_version, "456000"], [last_installed_version, "456000"],
] ]
} }
let(:caskroom_path) { Hbc.caskroom.join(token).tap(&:mkpath) } let(:caskroom_path) { Hbc::Caskroom.path.join(token).tap(&:mkpath) }
before do before do
timestamped_versions.each do |timestamped_version| timestamped_versions.each do |timestamped_version|
@ -143,7 +143,7 @@ describe Hbc::CLI::Uninstall, :cask do
describe "when Casks in Taps have been renamed or removed" do describe "when Casks in Taps have been renamed or removed" do
let(:app) { Hbc::Config.global.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(:caskroom_path) { Hbc::Caskroom.path.join("ive-been-renamed").tap(&:mkpath) }
let(:saved_caskfile) { caskroom_path.join(".metadata", "latest", "timestamp", "Casks").join("ive-been-renamed.rb") } let(:saved_caskfile) { caskroom_path.join(".metadata", "latest", "timestamp", "Casks").join("ive-been-renamed.rb") }
before do before do

View File

@ -9,7 +9,7 @@ describe Hbc::Installer, :cask do
Hbc::Installer.new(caffeine).install Hbc::Installer.new(caffeine).install
expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine", caffeine.version)).to be_a_directory
expect(Hbc::Config.global.appdir.join("Caffeine.app")).to be_a_directory expect(Hbc::Config.global.appdir.join("Caffeine.app")).to be_a_directory
end end
@ -18,7 +18,7 @@ describe Hbc::Installer, :cask do
Hbc::Installer.new(asset).install Hbc::Installer.new(asset).install
expect(Hbc.caskroom.join("container-dmg", asset.version)).to be_a_directory expect(Hbc::Caskroom.path.join("container-dmg", asset.version)).to be_a_directory
expect(Hbc::Config.global.appdir.join("container")).to be_a_file expect(Hbc::Config.global.appdir.join("container")).to be_a_file
end end
@ -27,7 +27,7 @@ describe Hbc::Installer, :cask do
Hbc::Installer.new(asset).install Hbc::Installer.new(asset).install
expect(Hbc.caskroom.join("container-tar-gz", asset.version)).to be_a_directory expect(Hbc::Caskroom.path.join("container-tar-gz", asset.version)).to be_a_directory
expect(Hbc::Config.global.appdir.join("container")).to be_a_file expect(Hbc::Config.global.appdir.join("container")).to be_a_file
end end
@ -36,7 +36,7 @@ describe Hbc::Installer, :cask do
Hbc::Installer.new(asset).install Hbc::Installer.new(asset).install
expect(Hbc.caskroom.join("container-xar", asset.version)).to be_a_directory expect(Hbc::Caskroom.path.join("container-xar", asset.version)).to be_a_directory
expect(Hbc::Config.global.appdir.join("container")).to be_a_file expect(Hbc::Config.global.appdir.join("container")).to be_a_file
end end
@ -45,7 +45,7 @@ describe Hbc::Installer, :cask do
Hbc::Installer.new(asset).install Hbc::Installer.new(asset).install
expect(Hbc.caskroom.join("container-bzip2", asset.version)).to be_a_directory expect(Hbc::Caskroom.path.join("container-bzip2", asset.version)).to be_a_directory
expect(Hbc::Config.global.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 end
@ -54,7 +54,7 @@ describe Hbc::Installer, :cask do
Hbc::Installer.new(asset).install Hbc::Installer.new(asset).install
expect(Hbc.caskroom.join("container-gzip", asset.version)).to be_a_directory expect(Hbc::Caskroom.path.join("container-gzip", asset.version)).to be_a_directory
expect(Hbc::Config.global.appdir.join("container")).to be_a_file expect(Hbc::Config.global.appdir.join("container")).to be_a_file
end end
@ -167,7 +167,7 @@ describe Hbc::Installer, :cask do
Hbc::Installer.new(naked_pkg).install Hbc::Installer.new(naked_pkg).install
expect(Hbc.caskroom.join("container-pkg", naked_pkg.version, "container.pkg")).to be_a_file expect(Hbc::Caskroom.path.join("container-pkg", naked_pkg.version, "container.pkg")).to be_a_file
end end
it "works properly with an overridden container :type" do it "works properly with an overridden container :type" do
@ -175,7 +175,7 @@ describe Hbc::Installer, :cask do
Hbc::Installer.new(naked_executable).install Hbc::Installer.new(naked_executable).install
expect(Hbc.caskroom.join("naked-executable", naked_executable.version, "naked_executable")).to be_a_file expect(Hbc::Caskroom.path.join("naked-executable", naked_executable.version, "naked_executable")).to be_a_file
end end
it "works fine with a nested container" do it "works fine with a nested container" do
@ -214,9 +214,9 @@ describe Hbc::Installer, :cask do
installer.install installer.install
installer.uninstall installer.uninstall
expect(Hbc.caskroom.join("local-caffeine", caffeine.version, "Caffeine.app")).not_to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine", caffeine.version, "Caffeine.app")).not_to be_a_directory
expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).not_to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine", caffeine.version)).not_to be_a_directory
expect(Hbc.caskroom.join("local-caffeine")).not_to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine")).not_to be_a_directory
end end
it "uninstalls all versions if force is set" do it "uninstalls all versions if force is set" do
@ -225,17 +225,17 @@ describe Hbc::Installer, :cask do
Hbc::Installer.new(caffeine).install Hbc::Installer.new(caffeine).install
expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine", caffeine.version)).to be_a_directory
expect(Hbc.caskroom.join("local-caffeine", mutated_version)).not_to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine", mutated_version)).not_to be_a_directory
FileUtils.mv(Hbc.caskroom.join("local-caffeine", caffeine.version), Hbc.caskroom.join("local-caffeine", mutated_version)) FileUtils.mv(Hbc::Caskroom.path.join("local-caffeine", caffeine.version), Hbc::Caskroom.path.join("local-caffeine", mutated_version))
expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).not_to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine", caffeine.version)).not_to be_a_directory
expect(Hbc.caskroom.join("local-caffeine", mutated_version)).to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine", mutated_version)).to be_a_directory
Hbc::Installer.new(caffeine, force: true).uninstall Hbc::Installer.new(caffeine, force: true).uninstall
expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).not_to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine", caffeine.version)).not_to be_a_directory
expect(Hbc.caskroom.join("local-caffeine", mutated_version)).not_to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine", mutated_version)).not_to be_a_directory
expect(Hbc.caskroom.join("local-caffeine")).not_to be_a_directory expect(Hbc::Caskroom.path.join("local-caffeine")).not_to be_a_directory
end end
end end
end end

View File

@ -23,9 +23,9 @@ RSpec.shared_context "Homebrew-Cask" do
begin begin
HOMEBREW_CASK_DIRS.values.each(&:mkpath) HOMEBREW_CASK_DIRS.values.each(&:mkpath)
[Hbc::Config.global.binarydir, Hbc.caskroom, Hbc.cache].each(&:mkpath) [Hbc::Config.global.binarydir, Hbc::Caskroom.path, Hbc::Cache.path].each(&:mkpath)
Hbc.default_tap = Tap.fetch("Homebrew", "cask-spec").tap do |tap| Tap.default_cask_tap.tap do |tap|
FileUtils.mkdir_p tap.path.dirname FileUtils.mkdir_p tap.path.dirname
FileUtils.ln_sf TEST_FIXTURE_DIR.join("cask"), tap.path FileUtils.ln_sf TEST_FIXTURE_DIR.join("cask"), tap.path
end end
@ -38,8 +38,8 @@ RSpec.shared_context "Homebrew-Cask" do
example.run example.run
ensure ensure
FileUtils.rm_rf HOMEBREW_CASK_DIRS.values FileUtils.rm_rf HOMEBREW_CASK_DIRS.values
FileUtils.rm_rf [Hbc::Config.global.binarydir, Hbc.caskroom, Hbc.cache] FileUtils.rm_rf [Hbc::Config.global.binarydir, Hbc::Caskroom.path, Hbc::Cache.path]
Hbc.default_tap.path.unlink Tap.default_cask_tap.path.unlink
third_party_tap.path.unlink third_party_tap.path.unlink
FileUtils.rm_rf third_party_tap.path.parent FileUtils.rm_rf third_party_tap.path.parent
end end