Merge pull request #16632 from reitermarkus/simplify-tests

Simplify tests.
This commit is contained in:
Kevin 2024-02-10 10:29:31 -08:00 committed by GitHub
commit 6797edf425
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 66 additions and 67 deletions

View File

@ -21,7 +21,7 @@ describe Cask::Artifact::Artifact, :cask do
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 @@ describe Cask::Artifact::Artifact, :cask do
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 @@ describe Cask::Artifact::Artifact, :cask do
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

View File

@ -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/)

View File

@ -518,61 +518,61 @@ describe Cask::Audit, :cask do
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

View File

@ -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 Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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 @@ describe Cask::DSL, :cask do
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/)

View File

@ -59,9 +59,11 @@ describe Cask::List, :cask do
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 @@ describe Cask::List, :cask do
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)

View File

@ -21,6 +21,14 @@ describe Cask::Upgrade, :cask do
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 @@ describe Cask::Upgrade, :cask do
]
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 @@ describe Cask::Upgrade, :cask do
]
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 @@ describe Cask::Upgrade, :cask do
]
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 @@ describe Cask::Upgrade, :cask do
]
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")

View File

@ -11,7 +11,7 @@ cask "livecheck-deprecated-reference" do
homepage "http://localhost/homebrew/test/cask/audit/livecheck/deprecated"
livecheck do
cask "livecheck/livecheck-deprecated"
cask "livecheck-deprecated"
end
app "TestCask.app"

View File

@ -11,7 +11,7 @@ cask "livecheck-disabled-reference" do
homepage "http://localhost/homebrew/test/cask/audit/livecheck/disabled"
livecheck do
cask "livecheck/livecheck-disabled"
cask "livecheck-disabled"
end
app "TestCask.app"

View File

@ -11,7 +11,7 @@ cask "livecheck-skip-reference" do
homepage "http://localhost/homebrew/test/cask/audit/livecheck/livecheck-skip"
livecheck do
cask "livecheck/livecheck-skip"
cask "livecheck-skip"
end
app "TestCask.app"

View File

@ -11,7 +11,7 @@ cask "livecheck-url-unversioned-reference" do
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"

View File

@ -11,7 +11,7 @@ cask "livecheck-version-latest-reference" do
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"

View File

@ -39,15 +39,26 @@ RSpec.shared_context "Homebrew Cask", :needs_macos do # rubocop:disable RSpec/Co
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