2017-03-05 19:26:56 +01:00
|
|
|
describe Hbc::Artifact::App, :cask do
|
2016-12-06 16:36:34 +01:00
|
|
|
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") }
|
2016-10-19 16:42:31 -04:00
|
|
|
let(:command) { Hbc::SystemCommand }
|
|
|
|
let(:force) { false }
|
2017-04-06 00:33:31 +02:00
|
|
|
let(:app) { described_class.for_cask(cask).first }
|
2016-10-19 16:42:31 -04:00
|
|
|
|
|
|
|
let(:source_path) { cask.staged_path.join("Caffeine.app") }
|
|
|
|
let(:target_path) { Hbc.appdir.join("Caffeine.app") }
|
|
|
|
|
2017-04-06 00:33:31 +02:00
|
|
|
let(:install_phase) { app.install_phase(command: command, force: force) }
|
|
|
|
let(:uninstall_phase) { app.uninstall_phase(command: command, force: force) }
|
2016-10-19 16:42:31 -04:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
before(:each) do
|
|
|
|
InstallHelper.install_without_artifacts(cask)
|
2016-10-19 16:42:31 -04:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-10-19 16:42:31 -04:00
|
|
|
describe "install_phase" do
|
|
|
|
it "installs the given app using the proper target directory" do
|
2017-07-29 19:55:05 +02:00
|
|
|
install_phase
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(target_path).to be_a_directory
|
|
|
|
expect(source_path).not_to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-10-19 16:42:31 -04:00
|
|
|
describe "when app is in a subdirectory" do
|
|
|
|
let(:cask) {
|
|
|
|
Hbc::Cask.new("subdir") do
|
2016-10-22 00:48:30 +02:00
|
|
|
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
|
2016-10-19 16:42:31 -04:00
|
|
|
homepage "http://example.com/local-caffeine"
|
|
|
|
version "1.2.3"
|
|
|
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
|
|
|
app "subdir/Caffeine.app"
|
|
|
|
end
|
|
|
|
}
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-10-19 16:42:31 -04:00
|
|
|
it "installs the given app using the proper target directory" do
|
|
|
|
appsubdir = cask.staged_path.join("subdir").tap(&:mkpath)
|
|
|
|
FileUtils.mv(source_path, appsubdir)
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-07-29 19:55:05 +02:00
|
|
|
install_phase
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(target_path).to be_a_directory
|
|
|
|
expect(appsubdir.join("Caffeine.app")).not_to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "only uses apps when they are specified" do
|
2016-10-19 16:42:31 -04:00
|
|
|
staged_app_copy = source_path.sub("Caffeine.app", "Caffeine Deluxe.app")
|
|
|
|
FileUtils.cp_r source_path, staged_app_copy
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-07-29 19:55:05 +02:00
|
|
|
install_phase
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(target_path).to be_a_directory
|
|
|
|
expect(source_path).not_to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist
|
|
|
|
expect(cask.staged_path.join("Caffeine Deluxe.app")).to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "when the target already exists" do
|
2017-02-08 14:23:18 +01:00
|
|
|
before(:each) do
|
2016-08-18 22:11:42 +03:00
|
|
|
target_path.mkpath
|
2016-10-19 16:42:31 -04:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
|
|
|
it "avoids clobbering an existing app" do
|
2017-03-10 09:33:48 +01:00
|
|
|
expect { install_phase }.to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path}'.")
|
2016-11-29 11:04:45 +01:00
|
|
|
|
2017-02-08 14:23:18 +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
|
|
|
|
|
|
|
contents_path = target_path.join("Contents/Info.plist")
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(contents_path).not_to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "given the force option" do
|
2016-10-19 16:42:31 -04:00
|
|
|
let(:force) { true }
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
before(:each) do
|
|
|
|
allow(Hbc::Utils).to receive(:current_user).and_return("fake_user")
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "target is both writable and user-owned" do
|
|
|
|
it "overwrites the existing app" do
|
2016-11-29 11:04:45 +01:00
|
|
|
stdout = <<-EOS.undent
|
2017-03-10 09:33:48 +01:00
|
|
|
==> Removing App '#{target_path}'.
|
|
|
|
==> Moving App 'Caffeine.app' to '#{target_path}'.
|
2016-10-19 16:42:31 -04:00
|
|
|
EOS
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-11-29 11:04:45 +01:00
|
|
|
stderr = <<-EOS.undent
|
|
|
|
Warning: It seems there is already an App at '#{target_path}'; overwriting.
|
|
|
|
EOS
|
|
|
|
|
2017-03-10 09:33:48 +01:00
|
|
|
expect { install_phase }
|
|
|
|
.to output(stdout).to_stdout
|
|
|
|
.and output(stderr).to_stderr
|
2016-11-29 11:04:45 +01:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(source_path).not_to exist
|
|
|
|
expect(target_path).to be_a_directory
|
2016-08-18 22:11:42 +03:00
|
|
|
|
|
|
|
contents_path = target_path.join("Contents/Info.plist")
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(contents_path).to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "target is user-owned but contains read-only files" do
|
2017-02-08 14:23:18 +01:00
|
|
|
before(:each) do
|
2017-04-06 00:33:31 +02:00
|
|
|
FileUtils.touch "#{target_path}/foo"
|
|
|
|
FileUtils.chmod 0555, target_path
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "overwrites the existing app" do
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(command).to receive(:run).with("/bin/chmod", args: ["-R", "--", "u+rwx", target_path], must_succeed: false)
|
|
|
|
.and_call_original
|
|
|
|
expect(command).to receive(:run).with("/bin/chmod", args: ["-R", "-N", target_path], must_succeed: false)
|
|
|
|
.and_call_original
|
|
|
|
expect(command).to receive(:run).with("/usr/bin/chflags", args: ["-R", "--", "000", target_path], must_succeed: false)
|
|
|
|
.and_call_original
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-11-29 11:04:45 +01:00
|
|
|
stdout = <<-EOS.undent
|
2017-03-10 09:33:48 +01:00
|
|
|
==> Removing App '#{target_path}'.
|
|
|
|
==> Moving App 'Caffeine.app' to '#{target_path}'.
|
2016-10-19 16:42:31 -04:00
|
|
|
EOS
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-11-29 11:04:45 +01:00
|
|
|
stderr = <<-EOS.undent
|
|
|
|
Warning: It seems there is already an App at '#{target_path}'; overwriting.
|
|
|
|
EOS
|
|
|
|
|
2017-03-10 09:33:48 +01:00
|
|
|
expect { install_phase }
|
|
|
|
.to output(stdout).to_stdout
|
|
|
|
.and output(stderr).to_stderr
|
2016-11-29 11:04:45 +01:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(source_path).not_to exist
|
|
|
|
expect(target_path).to be_a_directory
|
2016-08-18 22:11:42 +03:00
|
|
|
|
|
|
|
contents_path = target_path.join("Contents/Info.plist")
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(contents_path).to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
after(:each) do
|
2017-04-06 00:33:31 +02:00
|
|
|
FileUtils.chmod 0755, target_path
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when the target is a broken symlink" do
|
2016-10-19 16:42:31 -04:00
|
|
|
let(:deleted_path) { cask.staged_path.join("Deleted.app") }
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
before(:each) do
|
2016-08-18 22:11:42 +03:00
|
|
|
deleted_path.mkdir
|
|
|
|
File.symlink(deleted_path, target_path)
|
|
|
|
deleted_path.rmdir
|
|
|
|
end
|
|
|
|
|
|
|
|
it "leaves the target alone" do
|
2017-03-10 09:33:48 +01:00
|
|
|
expect { install_phase }.to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path}'.")
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(target_path).to be_a_symlink
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "given the force option" do
|
2016-10-19 16:42:31 -04:00
|
|
|
let(:force) { true }
|
2016-08-18 22:11:42 +03:00
|
|
|
|
|
|
|
it "overwrites the existing app" do
|
2016-11-29 11:04:45 +01:00
|
|
|
stdout = <<-EOS.undent
|
2017-03-10 09:33:48 +01:00
|
|
|
==> Removing App '#{target_path}'.
|
|
|
|
==> Moving App 'Caffeine.app' to '#{target_path}'.
|
2016-10-19 16:42:31 -04:00
|
|
|
EOS
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-11-29 11:04:45 +01:00
|
|
|
stderr = <<-EOS.undent
|
|
|
|
Warning: It seems there is already an App at '#{target_path}'; overwriting.
|
|
|
|
EOS
|
|
|
|
|
2017-03-10 09:33:48 +01:00
|
|
|
expect { install_phase }
|
|
|
|
.to output(stdout).to_stdout
|
|
|
|
.and output(stderr).to_stderr
|
2016-11-29 11:04:45 +01:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(source_path).not_to exist
|
|
|
|
expect(target_path).to be_a_directory
|
2016-08-18 22:11:42 +03:00
|
|
|
|
|
|
|
contents_path = target_path.join("Contents/Info.plist")
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(contents_path).to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gives a warning if the source doesn't exist" do
|
2016-10-19 16:42:31 -04:00
|
|
|
source_path.rmtree
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-03-10 09:33:48 +01:00
|
|
|
message = "It seems the App source '#{source_path}' is not there."
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-03-10 09:33:48 +01:00
|
|
|
expect { install_phase }.to raise_error(Hbc::CaskError, message)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "uninstall_phase" do
|
2017-02-08 14:23:18 +01:00
|
|
|
it "deletes managed apps" do
|
2017-07-29 19:55:05 +02:00
|
|
|
install_phase
|
2016-10-19 16:42:31 -04:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(target_path).to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-07-29 19:55:05 +02:00
|
|
|
uninstall_phase
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(target_path).not_to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "summary" do
|
2017-04-06 00:33:31 +02:00
|
|
|
let(:description) { app.class.english_description }
|
|
|
|
let(:contents) { app.summarize_installed }
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-10-19 16:42:31 -04:00
|
|
|
it "returns the correct english_description" do
|
2017-02-08 14:23:18 +01:00
|
|
|
expect(description).to eq("Apps")
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "app is correctly installed" do
|
2017-02-08 14:23:18 +01:00
|
|
|
it "returns the path to the app" do
|
2017-07-29 19:55:05 +02:00
|
|
|
install_phase
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-04-06 00:33:31 +02:00
|
|
|
expect(contents).to eq("#{target_path} (#{target_path.abv})")
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "app is missing" do
|
|
|
|
it "returns a warning and the supposed path to the app" do
|
2017-04-06 00:33:31 +02:00
|
|
|
expect(contents).to match(/.*Missing App.*: #{target_path}/)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|