104 lines
3.3 KiB
Ruby
Raw Normal View History

2017-03-05 19:26:56 +01:00
describe Hbc::Artifact::Binary, :cask do
2016-08-18 22:11:42 +03:00
let(:cask) {
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-binary.rb").tap do |cask|
2017-07-29 19:55:05 +02:00
InstallHelper.install_without_artifacts(cask)
2016-08-18 22:11:42 +03:00
end
}
2017-04-21 14:50:23 +02:00
let(:expected_path) { Hbc.binarydir.join("binary") }
2017-03-08 16:35:02 +01:00
2016-08-18 22:11:42 +03:00
before(:each) do
Hbc.binarydir.mkpath
end
2017-03-08 16:35:02 +01:00
2016-08-18 22:11:42 +03:00
after(:each) do
FileUtils.rm expected_path if expected_path.exist?
end
2017-05-19 19:13:23 +02:00
context "when --no-binaries is specified" do
let(:cask) {
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-binary.rb")
}
it "doesn't link the binary when --no-binaries is specified" do
2017-07-29 19:55:05 +02:00
Hbc::Installer.new(cask, binaries: false).install
2017-05-19 19:13:23 +02:00
expect(expected_path).not_to exist
end
end
2016-08-18 22:11:42 +03:00
it "links the binary to the proper directory" do
described_class.for_cask(cask)
.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) }
2017-07-29 19:55:05 +02:00
expect(expected_path).to be_a_symlink
expect(expected_path.readlink).to exist
2016-08-18 22:11:42 +03:00
end
2017-04-21 14:50:23 +02:00
context "when the binary is not executable" do
let(:cask) {
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-non-executable-binary.rb").tap do |cask|
2017-07-29 19:55:05 +02:00
InstallHelper.install_without_artifacts(cask)
2017-04-21 14:50:23 +02:00
end
}
2017-03-08 16:35:02 +01:00
2017-04-21 14:50:23 +02:00
let(:expected_path) { Hbc.binarydir.join("naked_non_executable") }
2017-03-08 16:35:02 +01:00
2017-04-21 14:50:23 +02:00
it "makes the binary executable" do
expect(FileUtils).to receive(:chmod)
.with("+x", cask.staged_path.join("naked_non_executable")).and_call_original
described_class.for_cask(cask)
.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) }
2017-04-21 14:50:23 +02:00
expect(expected_path).to be_a_symlink
expect(expected_path.readlink).to be_executable
end
2017-03-08 16:35:02 +01:00
end
2016-08-18 22:11:42 +03:00
it "avoids clobbering an existing binary by linking over it" do
FileUtils.touch expected_path
2016-11-29 11:04:45 +01:00
expect {
described_class.for_cask(cask)
.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) }
2016-11-29 11:04:45 +01:00
}.to raise_error(Hbc::CaskError)
2016-08-18 22:11:42 +03:00
2016-08-27 11:52:14 +02:00
expect(expected_path).not_to be :symlink?
2016-08-18 22:11:42 +03:00
end
it "clobbers an existing symlink" do
expected_path.make_symlink("/tmp")
described_class.for_cask(cask)
.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) }
2016-08-18 22:11:42 +03:00
expect(File.readlink(expected_path)).not_to eq("/tmp")
end
it "creates parent directory if it doesn't exist" do
FileUtils.rmdir Hbc.binarydir
described_class.for_cask(cask)
.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) }
2016-08-18 22:11:42 +03:00
expect(expected_path.exist?).to be true
end
context "binary is inside an app package" do
let(:cask) {
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-embedded-binary.rb").tap do |cask|
2017-07-29 19:55:05 +02:00
InstallHelper.install_without_artifacts(cask)
2016-08-18 22:11:42 +03:00
end
}
it "links the binary to the proper directory" do
Hbc::Artifact::App.for_cask(cask)
.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) }
described_class.for_cask(cask)
.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) }
2016-08-18 22:11:42 +03:00
expect(expected_path).to be_a_symlink
expect(expected_path.readlink).to exist
2016-08-18 22:11:42 +03:00
end
end
end