brew/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb

64 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
RSpec.describe Cask::Artifact::Artifact, :cask do
2018-09-06 08:29:14 +02:00
let(:cask) { Cask::CaskLoader.load(cask_path("with-generic-artifact")) }
let(:install_phase) do
2017-10-04 17:54:52 +02:00
lambda do
cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
2017-10-04 17:54:52 +02:00
end
end
end
2016-08-18 22:11:42 +03:00
let(:source_path) { cask.staged_path.join("Caffeine.app") }
2019-02-02 17:11:37 +01:00
let(:target_path) { cask.config.appdir.join("Caffeine.app") }
before do
2017-02-08 14:25:50 +01:00
InstallHelper.install_without_artifacts(cask)
end
context "without target" do
2025-06-11 19:44:26 -04:00
it "fails to load", :no_api do
expect do
Cask::CaskLoader.load("invalid-generic-artifact-no-target")
end.to raise_error(Cask::CaskInvalidError, /Generic Artifact.*requires.*target/)
2020-12-13 03:12:30 +01:00
end
end
context "with relative target" do
it "does not fail to load" do
expect do
Cask::CaskLoader.load("generic-artifact-relative-target")
end.not_to raise_error
2020-12-13 03:12:30 +01:00
end
end
context "with user-relative target" do
it "does not fail to load" do
expect do
Cask::CaskLoader.load("generic-artifact-user-relative-target")
end.not_to raise_error
end
2016-08-18 22:11:42 +03:00
end
it "moves the artifact to the proper directory" do
2017-07-29 19:55:05 +02:00
install_phase.call
2016-08-18 22:11:42 +03:00
2017-02-08 14:25:50 +01:00
expect(target_path).to be_a_directory
expect(source_path).to be_a_symlink
2016-08-18 22:11:42 +03:00
end
it "avoids clobbering an existing artifact" do
target_path.mkpath
2016-08-18 22:11:42 +03:00
expect do
2017-07-29 19:55:05 +02:00
install_phase.call
end.to raise_error(Cask::CaskError)
2016-08-18 22:11:42 +03:00
2017-02-08 14:25:50 +01:00
expect(source_path).to be_a_directory
expect(target_path).to be_a_directory
expect(File.identical?(source_path, target_path)).to be false
2016-08-18 22:11:42 +03:00
end
end