| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe Cask::Installer, :cask do | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   describe "install" do | 
					
						
							|  |  |  |     it "downloads and installs a nice fresh Cask" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(caffeine).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Caskroom.path.join("local-caffeine", caffeine.version)).to be_a_directory | 
					
						
							| 
									
										
										
										
											2019-02-02 17:11:37 +01:00
										 |  |  |       expect(caffeine.config.appdir.join("Caffeine.app")).to be_a_directory | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-29 23:17:21 -07:00
										 |  |  |     it "works with HFS+ dmg-based Casks" do | 
					
						
							|  |  |  |       asset = Cask::CaskLoader.load(cask_path("container-dmg")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       described_class.new(asset).install | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(Cask::Caskroom.path.join("container-dmg", asset.version)).to be_a_directory | 
					
						
							|  |  |  |       expect(asset.config.appdir.join("container")).to be_a_file | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-20 00:03:11 +02:00
										 |  |  |     it "works with tar-gz-based Casks" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       asset = Cask::CaskLoader.load(cask_path("container-tar-gz")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(asset).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Caskroom.path.join("container-tar-gz", asset.version)).to be_a_directory | 
					
						
							| 
									
										
										
										
											2019-02-02 17:11:37 +01:00
										 |  |  |       expect(asset.config.appdir.join("container")).to be_a_file | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "works with xar-based Casks" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       asset = Cask::CaskLoader.load(cask_path("container-xar")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(asset).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Caskroom.path.join("container-xar", asset.version)).to be_a_directory | 
					
						
							| 
									
										
										
										
											2019-02-02 17:11:37 +01:00
										 |  |  |       expect(asset.config.appdir.join("container")).to be_a_file | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-20 00:03:11 +02:00
										 |  |  |     it "works with pure bzip2-based Casks" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       asset = Cask::CaskLoader.load(cask_path("container-bzip2")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(asset).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Caskroom.path.join("container-bzip2", asset.version)).to be_a_directory | 
					
						
							| 
									
										
										
										
											2019-02-02 17:11:37 +01:00
										 |  |  |       expect(asset.config.appdir.join("container")).to be_a_file | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-20 00:03:11 +02:00
										 |  |  |     it "works with pure gzip-based Casks" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       asset = Cask::CaskLoader.load(cask_path("container-gzip")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(asset).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Caskroom.path.join("container-gzip", asset.version)).to be_a_directory | 
					
						
							| 
									
										
										
										
											2019-02-02 17:11:37 +01:00
										 |  |  |       expect(asset.config.appdir.join("container")).to be_a_file | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "blows up on a bad checksum" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       bad_checksum = Cask::CaskLoader.load(cask_path("bad-checksum")) | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |         described_class.new(bad_checksum).install | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.to raise_error(ChecksumMismatchError) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "blows up on a missing checksum" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       missing_checksum = Cask::CaskLoader.load(cask_path("missing-checksum")) | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |         described_class.new(missing_checksum).install | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.to output(/Cannot verify integrity/).to_stderr | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "installs fine if sha256 :no_check is used" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       no_checksum = Cask::CaskLoader.load(cask_path("no-checksum")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(no_checksum).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 11:52:20 +01:00
										 |  |  |       expect(no_checksum).to be_installed | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "fails to install if sha256 :no_check is used with --require-sha" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       no_checksum = Cask::CaskLoader.load(cask_path("no-checksum")) | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |         described_class.new(no_checksum, require_sha: true).install | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.to raise_error(/--require-sha/) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "installs fine if sha256 :no_check is used with --require-sha and --force" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       no_checksum = Cask::CaskLoader.load(cask_path("no-checksum")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(no_checksum, require_sha: true, force: true).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 11:52:20 +01:00
										 |  |  |       expect(no_checksum).to be_installed | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "prints caveats if they're present" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       with_caveats = Cask::CaskLoader.load(cask_path("with-caveats")) | 
					
						
							| 
									
										
										
										
											2017-02-05 08:51:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |         described_class.new(with_caveats).install | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.to output(/Here are some things you might want to know/).to_stdout | 
					
						
							| 
									
										
										
										
											2017-02-05 08:51:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 11:52:20 +01:00
										 |  |  |       expect(with_caveats).to be_installed | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "prints installer :manual instructions when present" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       with_installer_manual = Cask::CaskLoader.load(cask_path("with-installer-manual")) | 
					
						
							| 
									
										
										
										
											2017-02-05 08:51:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |         described_class.new(with_installer_manual).install | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.to output( | 
					
						
							| 
									
										
										
										
											2019-02-11 09:50:09 +00:00
										 |  |  |         <<~EOS, | 
					
						
							| 
									
										
										
										
											2019-10-09 20:39:59 +01:00
										 |  |  |           ==> Downloading file://#{HOMEBREW_LIBRARY_PATH}/test/support/fixtures/cask/caffeine.zip | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |           ==> Installing Cask with-installer-manual | 
					
						
							| 
									
										
										
										
											2023-04-14 20:07:01 +02:00
										 |  |  |           Cask with-installer-manual only provides a manual installer. To run it and complete the installation: | 
					
						
							|  |  |  |             open #{with_installer_manual.staged_path.join("Caffeine.app")} | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |           🍺  with-installer-manual was successfully installed! | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |       ).to_stdout | 
					
						
							| 
									
										
										
										
											2017-02-05 08:51:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 11:52:20 +01:00
										 |  |  |       expect(with_installer_manual).to be_installed | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "does not extract __MACOSX directories from zips" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       with_macosx_dir = Cask::CaskLoader.load(cask_path("with-macosx-dir")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(with_macosx_dir).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 11:52:20 +01:00
										 |  |  |       expect(with_macosx_dir.staged_path.join("__MACOSX")).not_to be_a_directory | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "allows already-installed Casks which auto-update to be installed if force is provided" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       with_auto_updates = Cask::CaskLoader.load(cask_path("auto-updates")) | 
					
						
							| 
									
										
										
										
											2017-02-05 08:51:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 11:52:20 +01:00
										 |  |  |       expect(with_auto_updates).not_to be_installed | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(with_auto_updates).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |         described_class.new(with_auto_updates, force: true).install | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.not_to raise_error | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "allows already-installed Casks to be installed if force is provided" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       transmission = Cask::CaskLoader.load(cask_path("local-transmission")) | 
					
						
							| 
									
										
										
										
											2017-02-05 08:51:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 11:52:20 +01:00
										 |  |  |       expect(transmission).not_to be_installed | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(transmission).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |         described_class.new(transmission, force: true).install | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.not_to raise_error | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-20 00:03:11 +02:00
										 |  |  |     it "works naked-pkg-based Casks" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       naked_pkg = Cask::CaskLoader.load(cask_path("container-pkg")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(naked_pkg).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Caskroom.path.join("container-pkg", naked_pkg.version, "container.pkg")).to be_a_file | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "works properly with an overridden container :type" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       naked_executable = Cask::CaskLoader.load(cask_path("naked-executable")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(naked_executable).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Caskroom.path.join("naked-executable", naked_executable.version, "naked_executable")).to be_a_file | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "works fine with a nested container" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       nested_app = Cask::CaskLoader.load(cask_path("nested-app")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(nested_app).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:46:30 +02:00
										 |  |  |       expect(nested_app.config.appdir.join("MyNestedApp.app")).to be_a_directory | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "generates and finds a timestamped metadata directory for an installed Cask" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(caffeine).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-20 10:48:32 +02:00
										 |  |  |       m_path = caffeine.metadata_timestamped_path(timestamp: :now, create: true) | 
					
						
							|  |  |  |       expect(caffeine.metadata_timestamped_path(timestamp: :latest)).to eq(m_path) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "generates and finds a metadata subdirectory for an installed Cask" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(caffeine).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       subdir_name = "Casks" | 
					
						
							| 
									
										
										
										
											2017-04-20 10:48:32 +02:00
										 |  |  |       m_subdir = caffeine.metadata_subdir(subdir_name, timestamp: :now, create: true) | 
					
						
							|  |  |  |       expect(caffeine.metadata_subdir(subdir_name, timestamp: :latest)).to eq(m_subdir) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2022-05-10 19:05:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "don't print cask installed message with --quiet option" do | 
					
						
							|  |  |  |       caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2022-05-10 19:05:32 +08:00
										 |  |  |         described_class.new(caffeine, quiet: true).install | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.to output(nil).to_stdout | 
					
						
							| 
									
										
										
										
											2022-05-10 19:05:32 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "does NOT generate LATEST_DOWNLOAD_SHA256 file for installed Cask without version :latest" do | 
					
						
							|  |  |  |       caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       described_class.new(caffeine).install | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(caffeine.download_sha_path).not_to be_a_file | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "generates and finds LATEST_DOWNLOAD_SHA256 file for installed Cask with version :latest" do | 
					
						
							|  |  |  |       latest_cask = Cask::CaskLoader.load(cask_path("version-latest")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       described_class.new(latest_cask).install | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(latest_cask.download_sha_path).to be_a_file | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-02-26 11:26:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     context "when loaded from the api and caskfile is required" do | 
					
						
							|  |  |  |       let(:path) { cask_path("local-caffeine") } | 
					
						
							|  |  |  |       let(:content) { File.read(path) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "installs cask" do | 
					
						
							| 
									
										
										
										
											2023-04-18 00:22:13 +01:00
										 |  |  |         source_caffeine = Cask::CaskLoader.load(path) | 
					
						
							|  |  |  |         expect(Homebrew::API::Cask).to receive(:source_download).once.and_return(source_caffeine) | 
					
						
							| 
									
										
										
										
											2023-02-26 11:26:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         caffeine = Cask::CaskLoader.load(path) | 
					
						
							| 
									
										
										
										
											2023-02-18 12:08:54 -08:00
										 |  |  |         expect(caffeine).to receive(:loaded_from_api?).once.and_return(true) | 
					
						
							| 
									
										
										
										
											2023-02-26 11:26:44 -08:00
										 |  |  |         expect(caffeine).to receive(:caskfile_only?).once.and_return(true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         described_class.new(caffeine).install | 
					
						
							|  |  |  |         expect(Cask::CaskLoader.load(path)).to be_installed | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-03-06 21:26:02 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 21:41:41 +09:00
										 |  |  |     it "zap method reinstall cask" do | 
					
						
							|  |  |  |       caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) | 
					
						
							|  |  |  |       described_class.new(caffeine).install | 
					
						
							| 
									
										
										
										
											2023-03-06 21:26:02 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 21:41:41 +09:00
										 |  |  |       expect(caffeine).to be_installed | 
					
						
							| 
									
										
										
										
											2023-03-06 21:26:02 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 21:41:41 +09:00
										 |  |  |       described_class.new(caffeine).zap | 
					
						
							| 
									
										
										
										
											2023-03-06 21:26:02 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-06 21:41:41 +09:00
										 |  |  |       expect(caffeine).not_to be_installed | 
					
						
							|  |  |  |       expect(caffeine.config.appdir.join("Caffeine.app")).not_to be_a_symlink | 
					
						
							| 
									
										
										
										
											2023-03-06 21:26:02 +09:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "uninstall" do | 
					
						
							|  |  |  |     it "fully uninstalls a Cask" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       installer = described_class.new(caffeine) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |       installer.install | 
					
						
							|  |  |  |       installer.uninstall | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Caskroom.path.join("local-caffeine", caffeine.version, "Caffeine.app")).not_to be_a_directory | 
					
						
							|  |  |  |       expect(Cask::Caskroom.path.join("local-caffeine", caffeine.version)).not_to be_a_directory | 
					
						
							|  |  |  |       expect(Cask::Caskroom.path.join("local-caffeine")).not_to be_a_directory | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "uninstalls all versions if force is set" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) | 
					
						
							| 
									
										
										
										
											2020-08-19 17:12:32 +01:00
										 |  |  |       mutated_version = "#{caffeine.version}.1" | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(caffeine).install | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Caskroom.path.join("local-caffeine", caffeine.version)).to be_a_directory | 
					
						
							|  |  |  |       expect(Cask::Caskroom.path.join("local-caffeine", mutated_version)).not_to be_a_directory | 
					
						
							|  |  |  |       FileUtils.mv(Cask::Caskroom.path.join("local-caffeine", caffeine.version), | 
					
						
							|  |  |  |                    Cask::Caskroom.path.join("local-caffeine", mutated_version)) | 
					
						
							|  |  |  |       expect(Cask::Caskroom.path.join("local-caffeine", caffeine.version)).not_to be_a_directory | 
					
						
							|  |  |  |       expect(Cask::Caskroom.path.join("local-caffeine", mutated_version)).to be_a_directory | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-23 17:09:57 +01:00
										 |  |  |       described_class.new(caffeine, force: true).uninstall | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Caskroom.path.join("local-caffeine", caffeine.version)).not_to be_a_directory | 
					
						
							|  |  |  |       expect(Cask::Caskroom.path.join("local-caffeine", mutated_version)).not_to be_a_directory | 
					
						
							|  |  |  |       expect(Cask::Caskroom.path.join("local-caffeine")).not_to be_a_directory | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-02-26 11:26:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     context "when loaded from the api, caskfile is required and installed caskfile is invalid" do | 
					
						
							|  |  |  |       let(:path) { cask_path("local-caffeine") } | 
					
						
							|  |  |  |       let(:content) { File.read(path) } | 
					
						
							|  |  |  |       let(:invalid_path) { instance_double(Pathname) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         allow(invalid_path).to receive(:exist?).and_return(false) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "uninstalls cask" do | 
					
						
							| 
									
										
										
										
											2023-04-18 00:22:13 +01:00
										 |  |  |         source_caffeine = Cask::CaskLoader.load(path) | 
					
						
							|  |  |  |         expect(Homebrew::API::Cask).to receive(:source_download).twice.and_return(source_caffeine) | 
					
						
							| 
									
										
										
										
											2023-02-26 11:26:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         caffeine = Cask::CaskLoader.load(path) | 
					
						
							| 
									
										
										
										
											2023-02-18 12:08:54 -08:00
										 |  |  |         expect(caffeine).to receive(:loaded_from_api?).twice.and_return(true) | 
					
						
							| 
									
										
										
										
											2023-02-26 11:26:44 -08:00
										 |  |  |         expect(caffeine).to receive(:caskfile_only?).twice.and_return(true) | 
					
						
							| 
									
										
										
										
											2023-07-23 18:21:15 -07:00
										 |  |  |         expect(caffeine).to receive(:installed_caskfile).once.and_return(invalid_path) | 
					
						
							| 
									
										
										
										
											2023-02-26 11:26:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         described_class.new(caffeine).install | 
					
						
							|  |  |  |         expect(Cask::CaskLoader.load(path)).to be_installed | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         described_class.new(caffeine).uninstall | 
					
						
							|  |  |  |         expect(Cask::CaskLoader.load(path)).not_to be_installed | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2022-05-02 21:00:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "uninstall_existing_cask" do | 
					
						
							|  |  |  |     it "uninstalls when cask file is outdated" do | 
					
						
							|  |  |  |       caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) | 
					
						
							|  |  |  |       described_class.new(caffeine).install | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(Cask::CaskLoader.load(cask_path("local-caffeine"))).to be_installed | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(caffeine).to receive(:installed?).once.and_return(true) | 
					
						
							|  |  |  |       outdate_caskfile = cask_path("invalid/invalid-depends-on-macos-bad-release") | 
					
						
							|  |  |  |       expect(caffeine).to receive(:installed_caskfile).once.and_return(outdate_caskfile) | 
					
						
							|  |  |  |       described_class.new(caffeine).uninstall_existing_cask | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(Cask::CaskLoader.load(cask_path("local-caffeine"))).not_to be_installed | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | end |