From cb5684831e30e133ea9d771d6354adaa7e0af8cc Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 07:31:12 +0200 Subject: [PATCH 1/6] Remove unused `Buffer` class. --- Library/Homebrew/cask/lib/hbc/utils.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index 0f44c0157f..01ab4dad7f 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -4,17 +4,6 @@ require "stringio" BUG_REPORTS_URL = "https://github.com/caskroom/homebrew-cask#reporting-bugs".freeze -class Buffer < StringIO - extend Predicable - - attr_predicate :tty? - - def initialize(tty = false) - super() - @tty = tty - end -end - # global methods def odebug(title, *sput) From 68eef4c74ea6e4c615fb62ca53091c8365f43a1e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 07:33:34 +0200 Subject: [PATCH 2/6] Add `.localized` to undeletable macOS paths. --- Library/Homebrew/cask/lib/hbc/macos.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/macos.rb b/Library/Homebrew/cask/lib/hbc/macos.rb index a9e9e0a243..c983c1e24e 100644 --- a/Library/Homebrew/cask/lib/hbc/macos.rb +++ b/Library/Homebrew/cask/lib/hbc/macos.rb @@ -238,26 +238,35 @@ module OS # TODO: There should be a way to specify a containing # directory under which nothing can be deleted. - UNDELETABLE_DIRS = [ + UNDELETABLE_PATHS = [ "~/", "~/Applications", + "~/Applications/.localized", "~/Desktop", + "~/Desktop/.localized", "~/Documents", + "~/Documents/.localized", "~/Downloads", + "~/Downloads/.localized", "~/Mail", "~/Movies", + "~/Movies/.localized", "~/Music", + "~/Music/.localized", "~/Music/iTunes", "~/Music/iTunes/iTunes Music", "~/Music/iTunes/Album Artwork", "~/News", "~/Pictures", + "~/Pictures/.localized", "~/Pictures/Desktops", "~/Pictures/Photo Booth", "~/Pictures/iChat Icons", "~/Pictures/iPhoto Library", "~/Public", + "~/Public/.localized", "~/Sites", + "~/Sites/.localized", "~/Library", "~/Library/.localized", "~/Library/Accessibility", @@ -364,17 +373,17 @@ module OS "~/Library/Widgets", "~/Library/Workflows", ] - .map { |x| Pathname(x.sub(%r{^~(?=(/|$))}, Dir.home)).expand_path } - .to_set - .union(SYSTEM_DIRS) - .freeze + .map { |path| Pathname(path.sub(%r{^~(?=(/|$))}, Dir.home)).expand_path } + .to_set + .union(SYSTEM_DIRS) + .freeze def system_dir?(dir) SYSTEM_DIRS.include?(Pathname.new(dir).expand_path) end - def undeletable?(dir) - UNDELETABLE_DIRS.include?(Pathname.new(dir).expand_path) + def undeletable?(path) + UNDELETABLE_PATHS.include?(Pathname.new(path).expand_path) end end end From 270d8882973805fded0f67e4b7a627ff5c1eae9c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 10:28:28 +0200 Subject: [PATCH 3/6] Make `Cask` `enumerable. --- Library/Homebrew/cask/lib/hbc/cask.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 681130c1b1..341f80047f 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -3,11 +3,20 @@ require "hbc/metadata" module Hbc class Cask + extend Enumerable extend Forwardable include Metadata attr_reader :token, :sourcefile_path, :config + def self.each + return to_enum unless block_given? + + Tap.flat_map(&:cask_files).each do |f| + yield CaskLoader::FromTapPathLoader.new(f).load + end + end + def tap return super if block_given? # Object#tap @tap @@ -43,10 +52,10 @@ module Hbc end def full_name - if @tap.nil? || @tap == Hbc.default_tap + if tap.nil? || tap == Hbc.default_tap token else - "#{@tap}/#{token}" + "#{tap.name}/#{token}" end end From 8d0d5eb6d9c6729142b17f5b64f95402efcce5e4 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 10:35:21 +0200 Subject: [PATCH 4/6] Remove `QualifiedToken`. --- Library/Homebrew/cask/lib/hbc.rb | 1 - Library/Homebrew/cask/lib/hbc/cli/info.rb | 12 ++++-------- Library/Homebrew/cask/lib/hbc/qualified_token.rb | 11 ----------- 3 files changed, 4 insertions(+), 20 deletions(-) delete mode 100644 Library/Homebrew/cask/lib/hbc/qualified_token.rb diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index 7547ea1e23..916a7ef349 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -19,7 +19,6 @@ require "hbc/locations" require "hbc/config" require "hbc/macos" require "hbc/pkg" -require "hbc/qualified_token" require "hbc/scopes" require "hbc/staged" require "hbc/system_command" diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index f12fe55648..991f0534ae 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -60,16 +60,12 @@ module Hbc end def self.repo_info(cask) - user, repo, token = QualifiedToken.parse(Hbc.all_tokens.detect { |t| t.split("/").last == cask.token }) + return if cask.tap.nil? - return if user.nil? || repo.nil? - - remote_tap = Tap.fetch(user, repo) - - url = if remote_tap.custom_remote? && !remote_tap.remote.nil? - remote_tap.remote + url = if cask.tap.custom_remote? && !cask.tap.remote.nil? + cask.tap.remote else - "#{remote_tap.default_remote}/blob/master/Casks/#{token}.rb" + "#{cask.tap.default_remote}/blob/master/Casks/#{cask.token}.rb" end puts "From: #{Formatter.url(url)}" diff --git a/Library/Homebrew/cask/lib/hbc/qualified_token.rb b/Library/Homebrew/cask/lib/hbc/qualified_token.rb deleted file mode 100644 index 09eedef1b3..0000000000 --- a/Library/Homebrew/cask/lib/hbc/qualified_token.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Hbc - module QualifiedToken - def self.parse(arg) - return nil unless arg.is_a?(String) - return nil unless match = arg.downcase.match(HOMEBREW_TAP_CASK_REGEX) - user, repo, token = match.captures - odebug "[user, repo, token] might be [#{user}, #{repo}, #{token}]" - [user, repo, token] - end - end -end From 791af7e910f36fdce6f17b3e82eb2cf08edbe8f4 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 11:29:14 +0200 Subject: [PATCH 5/6] Move invalid Cask fixtures into sub-directories. --- .../Homebrew/test/cask/artifact/generic_artifact_spec.rb | 2 +- .../test/cask/artifact/two_apps_incorrect_spec.rb | 9 --------- Library/Homebrew/test/cask/dsl_spec.rb | 2 +- .../fixtures/cask/Casks/{ => compat}/with-dsl-version.rb | 0 .../fixtures/cask/Casks/generic-artifact-no-target.rb | 3 --- .../invalid-generic-artifact-no-target.rb} | 2 +- .../fixtures/cask/Casks/with-two-apps-incorrect.rb | 9 --------- 7 files changed, 3 insertions(+), 24 deletions(-) delete mode 100644 Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb rename Library/Homebrew/test/support/fixtures/cask/Casks/{ => compat}/with-dsl-version.rb (100%) delete mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-no-target.rb rename Library/Homebrew/test/support/fixtures/cask/Casks/{with-generic-artifact-no-target.rb => invalid/invalid-generic-artifact-no-target.rb} (83%) delete mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-incorrect.rb diff --git a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb index 7e12854760..5502d83ed7 100644 --- a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb +++ b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb @@ -19,7 +19,7 @@ describe Hbc::Artifact::Artifact, :cask do context "without target" do it "fails to load" do expect { - Hbc::CaskLoader.load(cask_path("with-generic-artifact-no-target")) + Hbc::CaskLoader.load(cask_path("invalid/invalid-generic-artifact-no-target")) }.to raise_error(Hbc::CaskInvalidError, /target required for Generic Artifact/) end end diff --git a/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb b/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb deleted file mode 100644 index cda5b4488c..0000000000 --- a/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -describe Hbc::Artifact::App, :cask do - # FIXME: Doesn't actually raise because the `app` stanza is not evaluated on load. - # it "must raise" do - # lambda { - # Hbc::CaskLoader.load(cask_path("with-two-apps-incorrect")) - # }.must_raise - # # TODO: later give the user a nice exception for this case and check for it here - # end -end diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 3e16b915ea..0348daab13 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -72,7 +72,7 @@ describe Hbc::DSL, :cask do end context "when it contains a deprecated DSL version", :needs_compat do - let(:token) { "with-dsl-version" } + let(:token) { "compat/with-dsl-version" } it "may use deprecated DSL version hash syntax" do allow(ENV).to receive(:[]).with("HOMEBREW_DEVELOPER").and_return(nil) diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-dsl-version.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/compat/with-dsl-version.rb similarity index 100% rename from Library/Homebrew/test/support/fixtures/cask/Casks/with-dsl-version.rb rename to Library/Homebrew/test/support/fixtures/cask/Casks/compat/with-dsl-version.rb diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-no-target.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-no-target.rb deleted file mode 100644 index a3e65caab2..0000000000 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-no-target.rb +++ /dev/null @@ -1,3 +0,0 @@ -cask 'generic-artifact-no-target' do - artifact 'Caffeine.app' -end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact-no-target.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-generic-artifact-no-target.rb similarity index 83% rename from Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact-no-target.rb rename to Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-generic-artifact-no-target.rb index f7f1ddc221..b806a94fca 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact-no-target.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-generic-artifact-no-target.rb @@ -1,4 +1,4 @@ -cask 'with-generic-artifact-no-target' do +cask 'invalid-generic-artifact-no-target' do version '1.2.3' sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94' diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-incorrect.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-incorrect.rb deleted file mode 100644 index c3ca473bda..0000000000 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-incorrect.rb +++ /dev/null @@ -1,9 +0,0 @@ -cask 'with-two-apps-incorrect' do - version '1.2.3' - sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94' - - url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" - homepage 'http://example.com/local-caffeine' - - app 'Caffeine.app', 'Caffeine.app/Contents/MacOS/Caffeine' -end From 19317760da43ab3e171df7904bde8d62bcc2257e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 14 Apr 2018 11:32:29 +0200 Subject: [PATCH 6/6] Remove `Hbc::Scopes`. --- Library/Homebrew/cask/lib/hbc.rb | 2 - Library/Homebrew/cask/lib/hbc/cask.rb | 12 +++-- Library/Homebrew/cask/lib/hbc/caskroom.rb | 12 +++++ Library/Homebrew/cask/lib/hbc/cli/audit.rb | 2 +- .../cask/lib/hbc/cli/internal_stanza.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/list.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/outdated.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/search.rb | 4 +- Library/Homebrew/cask/lib/hbc/cli/style.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/upgrade.rb | 2 +- Library/Homebrew/cask/lib/hbc/scopes.rb | 47 ------------------- Library/Homebrew/test/cask/cask_spec.rb | 8 ---- Library/Homebrew/test/cask/cli/audit_spec.rb | 4 +- Library/Homebrew/test/cask/cli/style_spec.rb | 8 ++-- Library/Homebrew/test/cask/scopes_spec.rb | 37 --------------- 15 files changed, 33 insertions(+), 113 deletions(-) delete mode 100644 Library/Homebrew/cask/lib/hbc/scopes.rb delete mode 100644 Library/Homebrew/test/cask/scopes_spec.rb diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index 916a7ef349..a013f4a323 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -19,7 +19,6 @@ require "hbc/locations" require "hbc/config" require "hbc/macos" require "hbc/pkg" -require "hbc/scopes" require "hbc/staged" require "hbc/system_command" require "hbc/topological_hash" @@ -30,7 +29,6 @@ require "hbc/version" module Hbc include Locations - include Scopes include Utils def self.init diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 341f80047f..410dcfe649 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -52,11 +52,13 @@ module Hbc end def full_name - if tap.nil? || tap == Hbc.default_tap - token - else - "#{tap.name}/#{token}" - end + return token if tap == Hbc.default_tap + qualified_token + end + + def qualified_token + return token if tap.nil? + "#{tap.name}/#{token}" end def installed? diff --git a/Library/Homebrew/cask/lib/hbc/caskroom.rb b/Library/Homebrew/cask/lib/hbc/caskroom.rb index b5c947f4b1..6c69e5fb8e 100644 --- a/Library/Homebrew/cask/lib/hbc/caskroom.rb +++ b/Library/Homebrew/cask/lib/hbc/caskroom.rb @@ -15,5 +15,17 @@ module Hbc SystemCommand.run("/usr/sbin/chown", args: [Utils.current_user, Hbc.caskroom], sudo: sudo) SystemCommand.run("/usr/bin/chgrp", args: ["admin", Hbc.caskroom], sudo: sudo) end + + def casks + Pathname.glob(Hbc.caskroom.join("*")).sort.select(&:directory?).map do |path| + token = path.basename.to_s + + if tap_path = CaskLoader.tap_paths(token).first + next CaskLoader::FromTapPathLoader.new(tap_path).load + end + + CaskLoader::FromPathLoader.new(Pathname.glob(path.join(".metadata/*/*/*/*.rb")).first).load + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/audit.rb b/Library/Homebrew/cask/lib/hbc/cli/audit.rb index 35d82800c6..2b89a8d2c3 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/audit.rb @@ -9,7 +9,7 @@ module Hbc end def run - failed_casks = casks(alternative: -> { Hbc.all }) + failed_casks = casks(alternative: -> { Cask.to_a }) .reject { |cask| audit(cask) } return if failed_casks.empty? diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index bdb1c0c30a..355f1a4d3f 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -58,7 +58,7 @@ module Hbc @stanza = :artifacts end - casks(alternative: -> { Hbc.all }).each do |cask| + casks(alternative: -> { Cask.to_a }).each do |cask| print "#{cask}\t" if table? begin diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 4a50ae74ad..788b0eede5 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -37,7 +37,7 @@ module Hbc end def list_installed - installed_casks = Hbc.installed + installed_casks = Caskroom.casks if one? puts installed_casks.map(&:to_s) diff --git a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb index b0a84e8d26..593fea19da 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb @@ -10,7 +10,7 @@ module Hbc end def run - casks(alternative: -> { Hbc.installed }).each do |cask| + casks(alternative: -> { Caskroom.casks }).each do |cask| odebug "Checking update info of Cask #{cask}" self.class.list_if_outdated(cask, greedy?, verbose?) end diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index d7fac8cd72..480d7b5e54 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -3,7 +3,7 @@ module Hbc class Search < AbstractCommand def run if args.empty? - puts Formatter.columns(CLI.nice_listing(Hbc.all_tokens)) + puts Formatter.columns(CLI.nice_listing(Cask.map(&:qualified_token))) else results = self.class.search(*args) self.class.render_results(*results) @@ -43,7 +43,7 @@ module Hbc partial_matches = [] search_term = arguments.join(" ") search_regexp = extract_regexp arguments.first - all_tokens = CLI.nice_listing(Hbc.all_tokens) + all_tokens = CLI.nice_listing(Cask.map(&:qualified_token)) if search_regexp search_term = arguments.first partial_matches = all_tokens.grep(/#{search_regexp}/i) diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb index 261bed50b9..cb2e5e0537 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/style.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb @@ -27,7 +27,7 @@ module Hbc def cask_paths @cask_paths ||= if args.empty? - Hbc.all_tapped_cask_dirs + Tap.map(&:cask_dir).select(&:directory?) elsif args.any? { |file| File.exist?(file) } args else diff --git a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb index 808b64c4b7..276b180aa1 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb @@ -13,7 +13,7 @@ module Hbc def run outdated_casks = casks(alternative: lambda { - Hbc.installed.select do |cask| + Caskroom.casks.select do |cask| cask.outdated?(greedy?) end }).select { |cask| cask.outdated?(true) } diff --git a/Library/Homebrew/cask/lib/hbc/scopes.rb b/Library/Homebrew/cask/lib/hbc/scopes.rb deleted file mode 100644 index a469ae0fa6..0000000000 --- a/Library/Homebrew/cask/lib/hbc/scopes.rb +++ /dev/null @@ -1,47 +0,0 @@ -module Hbc - module Scopes - def self.included(base) - base.extend(ClassMethods) - end - - module ClassMethods - def all - all_tokens.map(&CaskLoader.public_method(:load)) - end - - def all_tapped_cask_dirs - Tap.map(&:cask_dir).select(&:directory?) - end - - def all_tokens - Tap.flat_map do |t| - t.cask_files.map do |p| - "#{t.name}/#{File.basename(p, ".rb")}" - end - end - end - - def installed - # CaskLoader.load has some DWIM which is slow. Optimize here - # by spoon-feeding CaskLoader.load fully-qualified paths. - # TODO: speed up Hbc::Source::Tapped (main perf drag is calling Hbc.all_tokens repeatedly) - # TODO: ability to specify expected source when calling CaskLoader.load (minor perf benefit) - Pathname.glob(caskroom.join("*")) - .sort - .map do |caskroom_path| - token = caskroom_path.basename.to_s - - path_to_cask = all_tapped_cask_dirs.find do |tap_dir| - tap_dir.join("#{token}.rb").exist? - end - - if path_to_cask - CaskLoader.load(path_to_cask.join("#{token}.rb")) - else - CaskLoader.load(token) - end - end - end - end - end -end diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index e8d5aff8f8..4b9393d6cc 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -70,14 +70,6 @@ describe Hbc::Cask, :cask do end end - describe "all_tokens" do - it "returns a token for every Cask" do - all_cask_tokens = Hbc.all_tokens - expect(all_cask_tokens.count).to be > 20 - all_cask_tokens.each { |token| expect(token).to be_kind_of(String) } - end - end - describe "metadata" do it "proposes a versioned metadata directory name for each instance" do cask_token = "local-caffeine" diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb index da8bf12737..2ed4ea9f11 100644 --- a/Library/Homebrew/test/cask/cli/audit_spec.rb +++ b/Library/Homebrew/test/cask/cli/audit_spec.rb @@ -7,9 +7,7 @@ describe Hbc::CLI::Audit, :cask do describe "selection of Casks to audit" do it "audits all Casks if no tokens are given" do - expect(cask).to be_a Hbc::Cask - - allow(Hbc).to receive(:all).and_return([cask, cask]) + allow(Hbc::Cask).to receive(:to_a).and_return([cask, cask]) expect(Hbc::Auditor).to receive(:audit).twice.and_return(true) diff --git a/Library/Homebrew/test/cask/cli/style_spec.rb b/Library/Homebrew/test/cask/cli/style_spec.rb index aaf3248f17..6f486ea939 100644 --- a/Library/Homebrew/test/cask/cli/style_spec.rb +++ b/Library/Homebrew/test/cask/cli/style_spec.rb @@ -83,11 +83,13 @@ describe Hbc::CLI::Style, :cask do context "when no cask tokens are given" do let(:tokens) { [] } - before do - allow(Hbc).to receive(:all_tapped_cask_dirs).and_return(%w[Casks MoreCasks]) + matcher :a_path_ending_with do |end_string| + match do |actual| + expect(actual.to_s).to end_with(end_string) + end end - it { is_expected.to eq(%w[Casks MoreCasks]) } + it { is_expected.to contain_exactly(a_path_ending_with("/caskroom/homebrew-spec/Casks"), a_path_ending_with("/third-party/homebrew-tap/Casks")) } end context "when at least one cask token is a path that exists" do diff --git a/Library/Homebrew/test/cask/scopes_spec.rb b/Library/Homebrew/test/cask/scopes_spec.rb deleted file mode 100644 index d1c03b9b0c..0000000000 --- a/Library/Homebrew/test/cask/scopes_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -describe Hbc::Scopes, :cask do - describe "installed" do - it "returns a list installed Casks by loading Casks for all the dirs that exist in the caskroom" do - allow(Hbc::CaskLoader).to receive(:load) { |token| "loaded-#{token}" } - - Hbc.caskroom.join("cask-bar").mkpath - Hbc.caskroom.join("cask-foo").mkpath - - installed_casks = Hbc.installed - - expect(Hbc::CaskLoader).to have_received(:load).with("cask-bar") - expect(Hbc::CaskLoader).to have_received(:load).with("cask-foo") - expect(installed_casks).to eq( - %w[ - loaded-cask-bar - loaded-cask-foo - ], - ) - end - - it "optimizes performance by resolving to a fully qualified path before calling Hbc::CaskLoader.load" do - fake_tapped_cask_dir = Pathname.new(Dir.mktmpdir).join("Casks") - absolute_path_to_cask = fake_tapped_cask_dir.join("some-cask.rb") - - allow(Hbc::CaskLoader).to receive(:load) - allow(Hbc).to receive(:all_tapped_cask_dirs) { [fake_tapped_cask_dir] } - - Hbc.caskroom.join("some-cask").mkdir - fake_tapped_cask_dir.mkdir - FileUtils.touch(absolute_path_to_cask) - - Hbc.installed - - expect(Hbc::CaskLoader).to have_received(:load).with(absolute_path_to_cask) - end - end -end