| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-07 22:17:07 +09:00
										 |  |  | require "cask/upgrade" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe Cask::Upgrade, :cask do | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |   let(:version_latest_paths) do | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |       version_latest.config.appdir.join("Caffeine Mini.app"), | 
					
						
							|  |  |  |       version_latest.config.appdir.join("Caffeine Pro.app"), | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-09-29 23:46:30 +02:00
										 |  |  |   let(:version_latest) { Cask::CaskLoader.load("version-latest") } | 
					
						
							|  |  |  |   let(:auto_updates_path) { auto_updates.config.appdir.join("MyFancyApp.app") } | 
					
						
							|  |  |  |   let(:auto_updates) { Cask::CaskLoader.load("auto-updates") } | 
					
						
							|  |  |  |   let(:local_transmission_path) { local_transmission.config.appdir.join("Transmission.app") } | 
					
						
							|  |  |  |   let(:local_transmission) { Cask::CaskLoader.load("local-transmission") } | 
					
						
							|  |  |  |   let(:local_caffeine_path) { local_caffeine.config.appdir.join("Caffeine.app") } | 
					
						
							|  |  |  |   let(:local_caffeine) { Cask::CaskLoader.load("local-caffeine") } | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  |   let(:renamed_app) { Cask::CaskLoader.load("renamed-app") } | 
					
						
							|  |  |  |   let(:renamed_app_old_path) { renamed_app.config.appdir.join("OldApp.app") } | 
					
						
							|  |  |  |   let(:renamed_app_new_path) { renamed_app.config.appdir.join("NewApp.app") } | 
					
						
							| 
									
										
										
										
											2023-03-07 22:17:07 +09:00
										 |  |  |   let(:args) { Homebrew::CLI::Args.new } | 
					
						
							| 
									
										
										
										
											2020-09-29 23:46:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-09 22:03:05 +01:00
										 |  |  |   before do | 
					
						
							|  |  |  |     installed.each do |cask| | 
					
						
							|  |  |  |       Cask::Installer.new(Cask::CaskLoader.load(cask_path(cask))).install | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |   context "when the upgrade is a dry run" do | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     let(:installed) do | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |       [ | 
					
						
							|  |  |  |         "outdated/local-caffeine", | 
					
						
							|  |  |  |         "outdated/local-transmission", | 
					
						
							|  |  |  |         "outdated/auto-updates", | 
					
						
							|  |  |  |         "outdated/version-latest", | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  |         "outdated/renamed-app", | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |       ] | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe 'without --greedy it ignores the Casks with "version latest" or "auto_updates true"' do | 
					
						
							|  |  |  |       it "would update all the installed Casks when no token is provided" do | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |         expect(described_class).not_to receive(:upgrade_cask) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |         expect(local_caffeine).to be_installed | 
					
						
							|  |  |  |         expect(local_caffeine_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_caffeine.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(local_transmission).to be_installed | 
					
						
							|  |  |  |         expect(local_transmission_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_transmission.installed_version).to eq "2.60" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  |         expect(renamed_app).to be_installed | 
					
						
							|  |  |  |         expect(renamed_app_old_path).to be_a_directory | 
					
						
							|  |  |  |         expect(renamed_app_new_path).not_to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(renamed_app.installed_version).to eq "1.0.0" | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |         described_class.upgrade_casks(dry_run: true, args:) | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(local_caffeine).to be_installed | 
					
						
							|  |  |  |         expect(local_caffeine_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_caffeine.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(local_transmission).to be_installed | 
					
						
							|  |  |  |         expect(local_transmission_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_transmission.installed_version).to eq "2.60" | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(renamed_app).to be_installed | 
					
						
							|  |  |  |         expect(renamed_app_old_path).to be_a_directory | 
					
						
							|  |  |  |         expect(renamed_app_new_path).not_to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(renamed_app.installed_version).to eq "1.0.0" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "would update only the Casks specified in the command line" do | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |         expect(described_class).not_to receive(:upgrade_cask) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |         expect(local_caffeine).to be_installed | 
					
						
							|  |  |  |         expect(local_caffeine_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_caffeine.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(local_transmission).to be_installed | 
					
						
							|  |  |  |         expect(local_transmission_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_transmission.installed_version).to eq "2.60" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |         described_class.upgrade_casks(local_caffeine, dry_run: true, args:) | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(local_caffeine).to be_installed | 
					
						
							|  |  |  |         expect(local_caffeine_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_caffeine.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(local_transmission).to be_installed | 
					
						
							|  |  |  |         expect(local_transmission_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_transmission.installed_version).to eq "2.60" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it 'would update "auto_updates" and "latest" Casks when their tokens are provided in the command line' do | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |         expect(described_class).not_to receive(:upgrade_cask) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:29 +01:00
										 |  |  |         expect(local_caffeine).to be_installed | 
					
						
							|  |  |  |         expect(local_caffeine_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_caffeine.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(auto_updates).to be_installed | 
					
						
							|  |  |  |         expect(auto_updates_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(auto_updates.installed_version).to eq "2.57" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  |         expect(renamed_app).to be_installed | 
					
						
							|  |  |  |         expect(renamed_app_old_path).to be_a_directory | 
					
						
							|  |  |  |         expect(renamed_app_new_path).not_to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(renamed_app.installed_version).to eq "1.0.0" | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |         described_class.upgrade_casks(local_caffeine, auto_updates, dry_run: true, args:) | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(local_caffeine).to be_installed | 
					
						
							|  |  |  |         expect(local_caffeine_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_caffeine.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(auto_updates).to be_installed | 
					
						
							|  |  |  |         expect(auto_updates_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(auto_updates.installed_version).to eq "2.57" | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(renamed_app).to be_installed | 
					
						
							|  |  |  |         expect(renamed_app_old_path).to be_a_directory | 
					
						
							|  |  |  |         expect(renamed_app_new_path).not_to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(renamed_app.installed_version).to eq "1.0.0" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:29 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "with --greedy it checks additional Casks" do | 
					
						
							|  |  |  |       it 'would include the Casks with "auto_updates true" or "version latest"' do | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |         expect(described_class).not_to receive(:upgrade_cask) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |         expect(local_caffeine).to be_installed | 
					
						
							|  |  |  |         expect(local_caffeine_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_caffeine.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(auto_updates).to be_installed | 
					
						
							|  |  |  |         expect(auto_updates_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(auto_updates.installed_version).to eq "2.57" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(local_transmission).to be_installed | 
					
						
							|  |  |  |         expect(local_transmission_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_transmission.installed_version).to eq "2.60" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  |         expect(renamed_app).to be_installed | 
					
						
							|  |  |  |         expect(renamed_app_old_path).to be_a_directory | 
					
						
							|  |  |  |         expect(renamed_app_new_path).not_to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(renamed_app.installed_version).to eq "1.0.0" | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |         expect(version_latest).to be_installed | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |         # Change download sha so that :latest cask decides to update itself | 
					
						
							|  |  |  |         version_latest.download_sha_path.write("fake download sha") | 
					
						
							|  |  |  |         expect(version_latest.outdated_download_sha?).to be(true) | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |         described_class.upgrade_casks(greedy: true, dry_run: true, args:) | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(local_caffeine).to be_installed | 
					
						
							|  |  |  |         expect(local_caffeine_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_caffeine.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(auto_updates).to be_installed | 
					
						
							|  |  |  |         expect(auto_updates_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(auto_updates.installed_version).to eq "2.57" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(local_transmission).to be_installed | 
					
						
							|  |  |  |         expect(local_transmission_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(local_transmission.installed_version).to eq "2.60" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  |         expect(renamed_app).to be_installed | 
					
						
							|  |  |  |         expect(renamed_app_old_path).to be_a_directory | 
					
						
							|  |  |  |         expect(renamed_app_new_path).not_to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(renamed_app.installed_version).to eq "1.0.0" | 
					
						
							| 
									
										
										
										
											2023-04-08 16:13:12 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |         expect(version_latest).to be_installed | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |         expect(version_latest.outdated_download_sha?).to be(true) | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |       it 'would update outdated Casks with "auto_updates true"' do | 
					
						
							|  |  |  |         expect(described_class).not_to receive(:upgrade_cask) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:46:30 +02:00
										 |  |  |         expect(auto_updates).to be_installed | 
					
						
							|  |  |  |         expect(auto_updates_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(auto_updates.installed_version).to eq "2.57" | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |         described_class.upgrade_casks(auto_updates, dry_run: true, greedy: true, args:) | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 23:46:30 +02:00
										 |  |  |         expect(auto_updates).to be_installed | 
					
						
							|  |  |  |         expect(auto_updates_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(auto_updates.installed_version).to eq "2.57" | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |       it 'would update outdated Casks with "version latest"' do | 
					
						
							|  |  |  |         expect(described_class).not_to receive(:upgrade_cask) | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |         expect(version_latest).to be_installed | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(version_latest_paths).to all be_a_directory | 
					
						
							|  |  |  |         expect(version_latest.installed_version).to eq "latest" | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |         # Change download sha so that :latest cask decides to update itself | 
					
						
							|  |  |  |         version_latest.download_sha_path.write("fake download sha") | 
					
						
							|  |  |  |         expect(version_latest.outdated_download_sha?).to be(true) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |         described_class.upgrade_casks(version_latest, dry_run: true, greedy: true, args:) | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(version_latest).to be_installed | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |         expect(version_latest_paths).to all be_a_directory | 
					
						
							|  |  |  |         expect(version_latest.installed_version).to eq "latest" | 
					
						
							| 
									
										
										
										
											2022-05-07 20:19:54 -07:00
										 |  |  |         expect(version_latest.outdated_download_sha?).to be(true) | 
					
						
							| 
									
										
										
										
											2020-06-29 09:50:18 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |   context "when an upgrade failed" do | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     let(:installed) do | 
					
						
							| 
									
										
										
										
											2017-11-27 01:29:08 +00:00
										 |  |  |       [ | 
					
						
							|  |  |  |         "outdated/bad-checksum", | 
					
						
							|  |  |  |         "outdated/will-fail-if-upgraded", | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-10-29 17:31:07 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-12 09:25:15 -03:00
										 |  |  |     output_reverted = Regexp.new <<~EOS | 
					
						
							|  |  |  |       Warning: Reverting upgrade for Cask .* | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 00:48:14 +00:00
										 |  |  |     it "restores the old Cask if the upgrade failed" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       will_fail_if_upgraded = Cask::CaskLoader.load("will-fail-if-upgraded") | 
					
						
							| 
									
										
										
										
											2019-02-02 17:11:37 +01:00
										 |  |  |       will_fail_if_upgraded_path = will_fail_if_upgraded.config.appdir.join("container") | 
					
						
							| 
									
										
										
										
											2017-11-24 01:21:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(will_fail_if_upgraded).to be_installed | 
					
						
							|  |  |  |       expect(will_fail_if_upgraded_path).to be_a_file | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       expect(will_fail_if_upgraded.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2017-11-12 09:25:15 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 20:55:33 +09:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |         described_class.upgrade_casks(will_fail_if_upgraded, args:) | 
					
						
							| 
									
										
										
										
											2023-03-09 20:55:33 +09:00
										 |  |  |       end.to raise_error(Cask::CaskError).and output(output_reverted).to_stderr | 
					
						
							| 
									
										
										
										
											2017-11-12 09:25:15 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 01:21:30 +00:00
										 |  |  |       expect(will_fail_if_upgraded).to be_installed | 
					
						
							|  |  |  |       expect(will_fail_if_upgraded_path).to be_a_file | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       expect(will_fail_if_upgraded.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       expect(will_fail_if_upgraded.staged_path).not_to exist | 
					
						
							| 
									
										
										
										
											2017-11-12 09:25:15 -03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 01:29:08 +00:00
										 |  |  |     it "does not restore the old Cask if the upgrade failed pre-install" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       bad_checksum = Cask::CaskLoader.load("bad-checksum") | 
					
						
							| 
									
										
										
										
											2019-02-02 17:11:37 +01:00
										 |  |  |       bad_checksum_path = bad_checksum.config.appdir.join("Caffeine.app") | 
					
						
							| 
									
										
										
										
											2017-11-24 01:21:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(bad_checksum).to be_installed | 
					
						
							|  |  |  |       expect(bad_checksum_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       expect(bad_checksum.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2017-11-12 09:25:15 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 20:55:33 +09:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |         described_class.upgrade_casks(bad_checksum, args:) | 
					
						
							| 
									
										
										
										
											2023-03-09 20:55:33 +09:00
										 |  |  |       end.to raise_error(ChecksumMismatchError).and(not_to_output(output_reverted).to_stderr) | 
					
						
							| 
									
										
										
										
											2017-11-12 09:25:15 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 01:21:30 +00:00
										 |  |  |       expect(bad_checksum).to be_installed | 
					
						
							|  |  |  |       expect(bad_checksum_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       expect(bad_checksum.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       expect(bad_checksum.staged_path).not_to exist | 
					
						
							| 
									
										
										
										
											2017-11-12 09:25:15 -03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |   context "when there were multiple failures" do | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     let(:installed) do | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  |       [ | 
					
						
							|  |  |  |         "outdated/bad-checksum", | 
					
						
							|  |  |  |         "outdated/local-transmission", | 
					
						
							|  |  |  |         "outdated/bad-checksum2", | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-06 09:54:29 -08:00
										 |  |  |     it "does not end the upgrade process" do | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  |       bad_checksum = Cask::CaskLoader.load("bad-checksum") | 
					
						
							|  |  |  |       bad_checksum_path = bad_checksum.config.appdir.join("Caffeine.app") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       bad_checksum_2 = Cask::CaskLoader.load("bad-checksum2") | 
					
						
							|  |  |  |       bad_checksum_2_path = bad_checksum_2.config.appdir.join("container") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(bad_checksum).to be_installed | 
					
						
							|  |  |  |       expect(bad_checksum_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       expect(bad_checksum.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(local_transmission).to be_installed | 
					
						
							|  |  |  |       expect(local_transmission_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       expect(local_transmission.installed_version).to eq "2.60" | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(bad_checksum_2).to be_installed | 
					
						
							|  |  |  |       expect(bad_checksum_2_path).to be_a_file | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       expect(bad_checksum_2.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 20:55:33 +09:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |         described_class.upgrade_casks(args:) | 
					
						
							| 
									
										
										
										
											2023-03-09 20:55:33 +09:00
										 |  |  |       end.to raise_error(Cask::MultipleCaskErrors) | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(bad_checksum).to be_installed | 
					
						
							|  |  |  |       expect(bad_checksum_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       expect(bad_checksum.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  |       expect(bad_checksum.staged_path).not_to exist | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(local_transmission).to be_installed | 
					
						
							|  |  |  |       expect(local_transmission_path).to be_a_directory | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       expect(local_transmission.installed_version).to eq "2.61" | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(bad_checksum_2).to be_installed | 
					
						
							|  |  |  |       expect(bad_checksum_2_path).to be_a_file | 
					
						
							| 
									
										
										
										
											2023-04-08 14:10:58 +02:00
										 |  |  |       expect(bad_checksum_2.installed_version).to eq "1.2.2" | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04:00
										 |  |  |       expect(bad_checksum_2.staged_path).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-10-29 17:31:07 -03:00
										 |  |  | end |