Skip to content

Commit

Permalink
Merge pull request Homebrew#16632 from reitermarkus/simplify-tests
Browse files Browse the repository at this point in the history
Simplify tests.
  • Loading branch information
apainintheneck authored Feb 10, 2024
2 parents 0782ba1 + d1fa91c commit 6797edf
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 67 deletions.
6 changes: 3 additions & 3 deletions Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
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

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

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
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/test/cask/artifact/manpage_spec.rb
Original file line number Diff line number Diff line change
@@ -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/)
Expand Down
20 changes: 10 additions & 10 deletions Library/Homebrew/test/cask/audit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions Library/Homebrew/test/cask/dsl_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -43,15 +43,15 @@

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)
end
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
Expand Down Expand Up @@ -309,31 +309,31 @@ 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/)
end
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/)
end
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/)
end
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/)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -410,15 +410,15 @@ 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)
end
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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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/)
Expand Down
14 changes: 11 additions & 3 deletions Library/Homebrew/test/cask/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
36 changes: 8 additions & 28 deletions Library/Homebrew/test/cask/upgrade_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit 6797edf

Please sign in to comment.