2017-03-05 19:26:56 +01:00
|
|
|
describe Hbc::CLI::Uninstall, :cask do
|
2017-03-18 18:57:04 -05:00
|
|
|
it "displays the uninstallation progress" do
|
|
|
|
caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
|
|
|
|
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::Installer.new(caffeine).install
|
2017-03-18 18:57:04 -05:00
|
|
|
|
|
|
|
output = Regexp.new <<-EOS.undent
|
|
|
|
==> Uninstalling Cask local-caffeine
|
2017-03-19 19:56:41 -05:00
|
|
|
==> Removing App '.*Caffeine.app'.
|
2017-03-18 18:57:04 -05:00
|
|
|
EOS
|
|
|
|
|
|
|
|
expect {
|
|
|
|
Hbc::CLI::Uninstall.run("local-caffeine")
|
|
|
|
}.to output(output).to_stdout
|
|
|
|
end
|
|
|
|
|
2016-08-18 22:11:42 +03:00
|
|
|
it "shows an error when a bad Cask is provided" do
|
2017-06-13 17:14:01 +02:00
|
|
|
expect { Hbc::CLI::Uninstall.run("notacask") }
|
2017-09-11 08:37:15 +02:00
|
|
|
.to raise_error(Hbc::CaskUnavailableError, /is unavailable/)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "shows an error when a Cask is provided that's not installed" do
|
2017-06-13 17:14:01 +02:00
|
|
|
expect { Hbc::CLI::Uninstall.run("local-caffeine") }
|
2017-09-11 08:37:15 +02:00
|
|
|
.to raise_error(Hbc::CaskNotInstalledError, /is not installed/)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "tries anyway on a non-present Cask when --force is given" do
|
2017-02-08 13:40:31 +01:00
|
|
|
expect {
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::CLI::Uninstall.run("local-caffeine", "--force")
|
2017-02-08 13:40:31 +01:00
|
|
|
}.not_to raise_error
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can uninstall and unlink multiple Casks at once" do
|
2016-12-06 16:36:34 +01:00
|
|
|
caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
|
|
|
|
transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::Installer.new(caffeine).install
|
|
|
|
Hbc::Installer.new(transmission).install
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 13:40:31 +01:00
|
|
|
expect(caffeine).to be_installed
|
|
|
|
expect(transmission).to be_installed
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::CLI::Uninstall.run("local-caffeine", "local-transmission")
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 13:40:31 +01:00
|
|
|
expect(caffeine).not_to be_installed
|
|
|
|
expect(Hbc.appdir.join("Transmission.app")).not_to exist
|
|
|
|
expect(transmission).not_to be_installed
|
|
|
|
expect(Hbc.appdir.join("Caffeine.app")).not_to exist
|
2017-02-16 17:46:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "calls `uninstall` before removing artifacts" do
|
|
|
|
cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script-app.rb")
|
|
|
|
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::Installer.new(cask).install
|
2017-02-16 17:46:23 +01:00
|
|
|
|
|
|
|
expect(cask).to be_installed
|
2017-03-10 09:33:48 +01:00
|
|
|
expect(Hbc.appdir.join("MyFancyApp.app")).to exist
|
2017-02-16 17:46:23 +01:00
|
|
|
|
|
|
|
expect {
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::CLI::Uninstall.run("with-uninstall-script-app")
|
2017-02-16 17:46:23 +01:00
|
|
|
}.not_to raise_error
|
|
|
|
|
|
|
|
expect(cask).not_to be_installed
|
|
|
|
expect(Hbc.appdir.join("MyFancyApp.app")).not_to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2017-02-16 22:00:29 +01:00
|
|
|
it "can uninstall Casks when the uninstall script is missing, but only when using `--force`" do
|
|
|
|
cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script-app.rb")
|
|
|
|
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::Installer.new(cask).install
|
2017-02-16 22:00:29 +01:00
|
|
|
|
|
|
|
expect(cask).to be_installed
|
|
|
|
|
|
|
|
Hbc.appdir.join("MyFancyApp.app").rmtree
|
|
|
|
|
2017-07-29 19:55:05 +02:00
|
|
|
expect { Hbc::CLI::Uninstall.run("with-uninstall-script-app") }
|
2017-09-11 08:37:15 +02:00
|
|
|
.to raise_error(Hbc::CaskError, /uninstall script .* does not exist/)
|
2017-02-16 22:00:29 +01:00
|
|
|
|
|
|
|
expect(cask).to be_installed
|
|
|
|
|
|
|
|
expect {
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::CLI::Uninstall.run("with-uninstall-script-app", "--force")
|
2017-02-16 22:00:29 +01:00
|
|
|
}.not_to raise_error
|
|
|
|
|
|
|
|
expect(cask).not_to be_installed
|
|
|
|
end
|
|
|
|
|
2016-08-18 22:11:42 +03:00
|
|
|
describe "when multiple versions of a cask are installed" do
|
|
|
|
let(:token) { "versioned-cask" }
|
|
|
|
let(:first_installed_version) { "1.2.3" }
|
|
|
|
let(:last_installed_version) { "4.5.6" }
|
|
|
|
let(:timestamped_versions) {
|
|
|
|
[
|
|
|
|
[first_installed_version, "123000"],
|
|
|
|
[last_installed_version, "456000"],
|
|
|
|
]
|
|
|
|
}
|
|
|
|
let(:caskroom_path) { Hbc.caskroom.join(token).tap(&:mkpath) }
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
timestamped_versions.each do |timestamped_version|
|
|
|
|
caskroom_path.join(".metadata", *timestamped_version, "Casks").tap(&:mkpath)
|
|
|
|
.join("#{token}.rb").open("w") do |caskfile|
|
2016-08-24 13:23:27 +02:00
|
|
|
caskfile.puts <<-EOS.undent
|
2016-08-18 22:11:42 +03:00
|
|
|
cask '#{token}' do
|
|
|
|
version '#{timestamped_version[0]}'
|
|
|
|
end
|
2016-08-24 13:23:27 +02:00
|
|
|
EOS
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
caskroom_path.join(timestamped_version[0]).mkpath
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uninstalls one version at a time" do
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::CLI::Uninstall.run("versioned-cask")
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 13:40:31 +01:00
|
|
|
expect(caskroom_path.join(first_installed_version)).to exist
|
|
|
|
expect(caskroom_path.join(last_installed_version)).not_to exist
|
|
|
|
expect(caskroom_path).to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::CLI::Uninstall.run("versioned-cask")
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 13:40:31 +01:00
|
|
|
expect(caskroom_path.join(first_installed_version)).not_to exist
|
|
|
|
expect(caskroom_path).not_to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "displays a message when versions remain installed" do
|
2017-02-08 13:40:31 +01:00
|
|
|
expect {
|
|
|
|
expect {
|
|
|
|
Hbc::CLI::Uninstall.run("versioned-cask")
|
|
|
|
}.not_to output.to_stderr
|
|
|
|
}.to output(/#{token} #{first_installed_version} is still installed./).to_stdout
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when Casks in Taps have been renamed or removed" do
|
|
|
|
let(:app) { Hbc.appdir.join("ive-been-renamed.app") }
|
|
|
|
let(:caskroom_path) { Hbc.caskroom.join("ive-been-renamed").tap(&:mkpath) }
|
|
|
|
let(:saved_caskfile) { caskroom_path.join(".metadata", "latest", "timestamp", "Casks").join("ive-been-renamed.rb") }
|
|
|
|
|
|
|
|
before do
|
|
|
|
app.tap(&:mkpath)
|
|
|
|
.join("Contents").tap(&:mkpath)
|
|
|
|
.join("Info.plist").tap(&FileUtils.method(:touch))
|
|
|
|
|
|
|
|
caskroom_path.mkpath
|
|
|
|
|
|
|
|
saved_caskfile.dirname.mkpath
|
|
|
|
|
2016-08-24 13:23:27 +02:00
|
|
|
IO.write saved_caskfile, <<-EOS.undent
|
2016-08-18 22:11:42 +03:00
|
|
|
cask 'ive-been-renamed' do
|
|
|
|
version :latest
|
|
|
|
|
|
|
|
app 'ive-been-renamed.app'
|
|
|
|
end
|
2016-08-24 13:23:27 +02:00
|
|
|
EOS
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can still uninstall those Casks" do
|
2017-07-29 19:55:05 +02:00
|
|
|
Hbc::CLI::Uninstall.run("ive-been-renamed")
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-08 13:40:31 +01:00
|
|
|
expect(app).not_to exist
|
|
|
|
expect(caskroom_path).not_to exist
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when no Cask is specified" do
|
|
|
|
it "raises an exception" do
|
2017-02-08 13:40:31 +01:00
|
|
|
expect {
|
2016-08-18 22:11:42 +03:00
|
|
|
Hbc::CLI::Uninstall.run
|
2017-02-08 13:40:31 +01:00
|
|
|
}.to raise_error(Hbc::CaskUnspecifiedError)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when no Cask is specified, but an invalid option" do
|
|
|
|
it "raises an exception" do
|
2017-02-08 13:40:31 +01:00
|
|
|
expect {
|
2016-08-18 22:11:42 +03:00
|
|
|
Hbc::CLI::Uninstall.run("--notavalidoption")
|
2017-05-21 02:32:46 +02:00
|
|
|
}.to raise_error(/invalid option/)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|