blob: 6a3f1da346e414f4f360b2e875bdee7b33231057 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
describe Hbc::Artifact::Binary, :cask do
let(:cask) {
Hbc::CaskLoader.load(cask_path("with-binary")).tap do |cask|
InstallHelper.install_without_artifacts(cask)
end
}
let(:artifacts) { cask.artifacts.select { |a| a.is_a?(described_class) } }
let(:expected_path) { Hbc.binarydir.join("binary") }
before(:each) do
Hbc.binarydir.mkpath
end
after(:each) do
FileUtils.rm expected_path if expected_path.exist?
end
context "when --no-binaries is specified" do
let(:cask) {
Hbc::CaskLoader.load(cask_path("with-binary"))
}
it "doesn't link the binary when --no-binaries is specified" do
Hbc::Installer.new(cask, binaries: false).install
expect(expected_path).not_to exist
end
end
it "links the binary to the proper directory" do
artifacts.each do |artifact|
artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false)
end
expect(expected_path).to be_a_symlink
expect(expected_path.readlink).to exist
end
context "when the binary is not executable" do
let(:cask) {
Hbc::CaskLoader.load(cask_path("with-non-executable-binary")).tap do |cask|
InstallHelper.install_without_artifacts(cask)
end
}
let(:expected_path) { Hbc.binarydir.join("naked_non_executable") }
it "makes the binary executable" do
expect(FileUtils).to receive(:chmod)
.with("+x", cask.staged_path.join("naked_non_executable")).and_call_original
artifacts.each do |artifact|
artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false)
end
expect(expected_path).to be_a_symlink
expect(expected_path.readlink).to be_executable
end
end
it "avoids clobbering an existing binary by linking over it" do
FileUtils.touch expected_path
expect {
artifacts.each do |artifact|
artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false)
end
}.to raise_error(Hbc::CaskError)
expect(expected_path).not_to be :symlink?
end
it "clobbers an existing symlink" do
expected_path.make_symlink("/tmp")
artifacts.each do |artifact|
artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false)
end
expect(File.readlink(expected_path)).not_to eq("/tmp")
end
it "creates parent directory if it doesn't exist" do
FileUtils.rmdir Hbc.binarydir
artifacts.each do |artifact|
artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false)
end
expect(expected_path.exist?).to be true
end
context "binary is inside an app package" do
let(:cask) {
Hbc::CaskLoader.load(cask_path("with-embedded-binary")).tap do |cask|
InstallHelper.install_without_artifacts(cask)
end
}
it "links the binary to the proper directory" do
cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) }.each do |artifact|
artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false)
end
artifacts.each do |artifact|
artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false)
end
expect(expected_path).to be_a_symlink
expect(expected_path.readlink).to exist
end
end
end
|