diff --git a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb index 0e9104f64d193..8b65307acb007 100644 --- a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb +++ b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb @@ -21,7 +21,7 @@ context "without target" do it "fails to load" do expect do - Cask::CaskLoader.load(cask_path("invalid/invalid-generic-artifact-no-target")) + Cask::CaskLoader.load("invalid-generic-artifact-no-target") end.to raise_error(Cask::CaskInvalidError, /Generic Artifact.*requires.*target/) end end @@ -29,7 +29,7 @@ context "with relative target" do it "does not fail to load" do expect do - Cask::CaskLoader.load(cask_path("generic-artifact-relative-target")) + Cask::CaskLoader.load("generic-artifact-relative-target") end.not_to raise_error end end @@ -37,7 +37,7 @@ context "with user-relative target" do it "does not fail to load" do expect do - Cask::CaskLoader.load(cask_path("generic-artifact-user-relative-target")) + Cask::CaskLoader.load("generic-artifact-user-relative-target") end.not_to raise_error end end diff --git a/Library/Homebrew/test/cask/artifact/manpage_spec.rb b/Library/Homebrew/test/cask/artifact/manpage_spec.rb index a803cf75863ac..79f5f0741becd 100644 --- a/Library/Homebrew/test/cask/artifact/manpage_spec.rb +++ b/Library/Homebrew/test/cask/artifact/manpage_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true describe Cask::Artifact::Manpage, :cask do - let(:cask) { Cask::CaskLoader.load(cask_path(cask_token)) } + let(:cask) { Cask::CaskLoader.load(cask_token) } context "without section" do - let(:cask_token) { "invalid/invalid-manpage-no-section" } + let(:cask_token) { "invalid-manpage-no-section" } it "fails to load a cask without section" do expect { cask }.to raise_error(Cask::CaskInvalidError, /is not a valid man page name/) diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index af6d944420eff..4819f81adec2b 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -518,61 +518,61 @@ def tmp_cask(name, text) let(:message) { /Version '[^']*' differs from '[^']*' retrieved by livecheck\./ } context "when the Cask has a livecheck block using skip" do - let(:cask_token) { "livecheck/livecheck-skip" } + let(:cask_token) { "livecheck-skip" } it { is_expected.not_to error_with(message) } end context "when the Cask has a livecheck block referencing a Cask using skip" do - let(:cask_token) { "livecheck/livecheck-skip-reference" } + let(:cask_token) { "livecheck-skip-reference" } it { is_expected.not_to error_with(message) } end context "when the Cask is deprecated" do - let(:cask_token) { "livecheck/livecheck-deprecated" } + let(:cask_token) { "livecheck-deprecated" } it { is_expected.not_to error_with(message) } end context "when the Cask has a livecheck block referencing a deprecated Cask" do - let(:cask_token) { "livecheck/livecheck-deprecated-reference" } + let(:cask_token) { "livecheck-deprecated-reference" } it { is_expected.not_to error_with(message) } end context "when the Cask is disabled" do - let(:cask_token) { "livecheck/livecheck-disabled" } + let(:cask_token) { "livecheck-disabled" } it { is_expected.not_to error_with(message) } end context "when the Cask has a livecheck block referencing a disabled Cask" do - let(:cask_token) { "livecheck/livecheck-disabled-reference" } + let(:cask_token) { "livecheck-disabled-reference" } it { is_expected.not_to error_with(message) } end context "when version is :latest" do - let(:cask_token) { "livecheck/livecheck-version-latest" } + let(:cask_token) { "livecheck-version-latest" } it { is_expected.not_to error_with(message) } end context "when the Cask has a livecheck block referencing a Cask where version is :latest" do - let(:cask_token) { "livecheck/livecheck-version-latest-reference" } + let(:cask_token) { "livecheck-version-latest-reference" } it { is_expected.not_to error_with(message) } end context "when url is unversioned" do - let(:cask_token) { "livecheck/livecheck-url-unversioned" } + let(:cask_token) { "livecheck-url-unversioned" } it { is_expected.not_to error_with(message) } end context "when the Cask has a livecheck block referencing a Cask with an unversioned url" do - let(:cask_token) { "livecheck/livecheck-url-unversioned-reference" } + let(:cask_token) { "livecheck-url-unversioned-reference" } it { is_expected.not_to error_with(message) } end diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 14db56d205293..bfdd15d0e8570 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe Cask::DSL, :cask do - let(:cask) { Cask::CaskLoader.load(cask_path(token.to_s)) } + let(:cask) { Cask::CaskLoader.load(token) } let(:token) { "basic-cask" } describe "stanzas" do @@ -43,7 +43,7 @@ describe "header line" do context "when invalid" do - let(:token) { "invalid/invalid-header-format" } + let(:token) { "invalid-header-format" } it "raises an error" do expect { cask }.to raise_error(Cask::CaskUnreadableError) @@ -51,7 +51,7 @@ end context "when token does not match the file name" do - let(:token) { "invalid/invalid-header-token-mismatch" } + let(:token) { "invalid-header-token-mismatch" } it "raises an error" do expect do @@ -309,7 +309,7 @@ def caveats end describe "url stanza" do - let(:token) { "invalid/invalid-two-url" } + let(:token) { "invalid-two-url" } it "prevents defining multiple urls" do expect { cask }.to raise_error(Cask::CaskInvalidError, /'url' stanza may only appear once/) @@ -317,7 +317,7 @@ def caveats end describe "homepage stanza" do - let(:token) { "invalid/invalid-two-homepage" } + let(:token) { "invalid-two-homepage" } it "prevents defining multiple homepages" do expect { cask }.to raise_error(Cask::CaskInvalidError, /'homepage' stanza may only appear once/) @@ -325,7 +325,7 @@ def caveats end describe "version stanza" do - let(:token) { "invalid/invalid-two-version" } + let(:token) { "invalid-two-version" } it "prevents defining multiple versions" do expect { cask }.to raise_error(Cask::CaskInvalidError, /'version' stanza may only appear once/) @@ -333,7 +333,7 @@ def caveats end describe "arch stanza" do - let(:token) { "invalid/invalid-two-arch" } + let(:token) { "invalid-two-arch" } it "prevents defining multiple arches" do expect { cask }.to raise_error(Cask::CaskInvalidError, /'arch' stanza may only appear once/) @@ -365,7 +365,7 @@ def caveats end describe "depends_on stanza" do - let(:token) { "invalid/invalid-depends-on-key" } + let(:token) { "invalid-depends-on-key" } it "refuses to load with an invalid depends_on key" do expect { cask }.to raise_error(Cask::CaskInvalidError) @@ -410,7 +410,7 @@ def caveats describe "depends_on macos" do context "when the depends_on macos value is invalid" do - let(:token) { "invalid/invalid-depends-on-macos-bad-release" } + let(:token) { "invalid-depends-on-macos-bad-release" } it "refuses to load" do expect { cask }.to raise_error(Cask::CaskInvalidError) @@ -418,7 +418,7 @@ def caveats end context "when there are conflicting depends_on macos forms" do - let(:token) { "invalid/invalid-depends-on-macos-conflicting-forms" } + let(:token) { "invalid-depends-on-macos-conflicting-forms" } it "refuses to load" do expect { cask }.to raise_error(Cask::CaskInvalidError) @@ -436,7 +436,7 @@ def caveats end context "with invalid depends_on arch value" do - let(:token) { "invalid/invalid-depends-on-arch-value" } + let(:token) { "invalid-depends-on-arch-value" } it "refuses to load" do expect { cask }.to raise_error(Cask::CaskInvalidError) @@ -454,7 +454,7 @@ def caveats end context "with invalid conflicts_with key" do - let(:token) { "invalid/invalid-conflicts-with-key" } + let(:token) { "invalid-conflicts-with-key" } it "refuses to load invalid conflicts_with key" do expect { cask }.to raise_error(Cask::CaskInvalidError) @@ -495,7 +495,7 @@ def caveats end context "when there is are activatable artifacts" do - let(:token) { "invalid/invalid-stage-only-conflict" } + let(:token) { "invalid-stage-only-conflict" } it "prevents specifying stage_only" do expect { cask }.to raise_error(Cask::CaskInvalidError, /'stage_only' must be the only activatable artifact/) diff --git a/Library/Homebrew/test/cask/list_spec.rb b/Library/Homebrew/test/cask/list_spec.rb index dd6d3a83c93cb..2b05119b3b860 100644 --- a/Library/Homebrew/test/cask/list_spec.rb +++ b/Library/Homebrew/test/cask/list_spec.rb @@ -59,9 +59,11 @@ end describe "lists versions" do - let!(:casks) do - ["local-caffeine", - "local-transmission"].map(&Cask::CaskLoader.method(:load)).each(&InstallHelper.method(:install_with_caskfile)) + let(:casks) do + [ + "local-caffeine", + "local-transmission", + ].map { |token| Cask::CaskLoader.load(token) } end let(:expected_output) do <<~EOS @@ -70,6 +72,12 @@ EOS end + before do + casks.each do |cask| + InstallHelper.install_with_caskfile(cask) + end + end + it "of all installed Casks" do expect do described_class.list_casks(versions: true) diff --git a/Library/Homebrew/test/cask/upgrade_spec.rb b/Library/Homebrew/test/cask/upgrade_spec.rb index fe9221deed2c1..35df63722f2fb 100644 --- a/Library/Homebrew/test/cask/upgrade_spec.rb +++ b/Library/Homebrew/test/cask/upgrade_spec.rb @@ -21,6 +21,14 @@ let(:renamed_app_new_path) { renamed_app.config.appdir.join("NewApp.app") } let(:args) { Homebrew::CLI::Args.new } + before do + installed.each do |cask| + Cask::Installer.new(Cask::CaskLoader.load(cask_path(cask))).install + end + + allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) + end + context "when the upgrade is successful" do let(:installed) do [ @@ -32,13 +40,6 @@ ] end - before do - installed.each { |cask| Cask::Installer.new(Cask::CaskLoader.load(cask_path(cask))).install } - FileUtils.rm_rf CoreCaskTap.instance.cask_dir/"outdated" - - allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) - end - 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 expect(local_caffeine).to be_installed @@ -226,13 +227,6 @@ ] end - before do - installed.each { |cask| Cask::Installer.new(Cask::CaskLoader.load(cask_path(cask))).install } - FileUtils.rm_rf CoreCaskTap.instance.cask_dir/"outdated" - - allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) - end - describe 'without --greedy it ignores the Casks with "version latest" or "auto_updates true"' do it "would update all the installed Casks when no token is provided" do expect(described_class).not_to receive(:upgrade_cask) @@ -412,13 +406,6 @@ ] end - before do - installed.each { |cask| Cask::Installer.new(Cask::CaskLoader.load(cask_path(cask))).install } - FileUtils.rm_rf CoreCaskTap.instance.cask_dir/"outdated" - - allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) - end - output_reverted = Regexp.new <<~EOS Warning: Reverting upgrade for Cask .* EOS @@ -469,13 +456,6 @@ ] end - before do - installed.each { |cask| Cask::Installer.new(Cask::CaskLoader.load(cask_path(cask))).install } - FileUtils.rm_rf CoreCaskTap.instance.cask_dir/"outdated" - - allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) - end - it "does not end the upgrade process" do bad_checksum = Cask::CaskLoader.load("bad-checksum") bad_checksum_path = bad_checksum.config.appdir.join("Caffeine.app") diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-deprecated-reference.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-deprecated-reference.rb index 47ba962ccb14e..8cc3718465c06 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-deprecated-reference.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-deprecated-reference.rb @@ -11,7 +11,7 @@ homepage "http://localhost/homebrew/test/cask/audit/livecheck/deprecated" livecheck do - cask "livecheck/livecheck-deprecated" + cask "livecheck-deprecated" end app "TestCask.app" diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-disabled-reference.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-disabled-reference.rb index 0a926cc525a5d..6218d47134c4b 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-disabled-reference.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-disabled-reference.rb @@ -11,7 +11,7 @@ homepage "http://localhost/homebrew/test/cask/audit/livecheck/disabled" livecheck do - cask "livecheck/livecheck-disabled" + cask "livecheck-disabled" end app "TestCask.app" diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-skip-reference.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-skip-reference.rb index 4514c358e6ab2..a6e32926c95dc 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-skip-reference.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-skip-reference.rb @@ -11,7 +11,7 @@ homepage "http://localhost/homebrew/test/cask/audit/livecheck/livecheck-skip" livecheck do - cask "livecheck/livecheck-skip" + cask "livecheck-skip" end app "TestCask.app" diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-url-unversioned-reference.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-url-unversioned-reference.rb index 1fe96752be927..5531bbfda6149 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-url-unversioned-reference.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-url-unversioned-reference.rb @@ -11,7 +11,7 @@ homepage "http://localhost/homebrew/test/cask/audit/livecheck/url-unversioned" livecheck do - cask "livecheck/livecheck-url-unversioned" + cask "livecheck-url-unversioned" end app "TestCask.app" diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-version-latest-reference.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-version-latest-reference.rb index ba3626a52b4b8..15bcf0f3685f9 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-version-latest-reference.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-version-latest-reference.rb @@ -11,7 +11,7 @@ homepage "http://localhost/homebrew/test/cask/audit/livecheck/version-latest" livecheck do - cask "livecheck/livecheck-version-latest" + cask "livecheck-version-latest" end app "TestCask.app" 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 67f9078c95015..b62d783305eef 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 @@ -39,15 +39,26 @@ class Config Cask::Config::DEFAULT_DIRS_PATHNAMES.each_value(&:mkpath) CoreCaskTap.instance.tap do |tap| - tap.cask_dir.mkpath - (TEST_FIXTURE_DIR/"cask/Casks").children.each do |casks_path| - FileUtils.ln_sf casks_path, tap.cask_dir + fixture_cask_dir = TEST_FIXTURE_DIR/"cask/Casks" + fixture_cask_dir.glob("**/*.rb").each do |fixture_cask_path| + relative_cask_path = fixture_cask_path.relative_path_from(fixture_cask_dir) + + # These are only used manually in tests since they + # would otherwise conflict with other casks. + next if relative_cask_path.dirname.basename.to_s == "outdated" + + cask_dir = (tap.cask_dir/relative_cask_path.dirname).tap(&:mkpath) + FileUtils.ln_sf fixture_cask_path, cask_dir end + + tap.clear_cache end third_party_tap.tap do |tap| tap.path.parent.mkpath FileUtils.ln_sf TEST_FIXTURE_DIR/"third-party", tap.path + + tap.clear_cache end example.run