| 
									
										
										
										
											2017-03-05 19:26:56 +01:00
										 |  |  | describe Hbc::Artifact::App, :cask do | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  |   describe "activate to alternate target" do | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |     let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-alt-target.rb") } | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let(:install_phase) { | 
					
						
							| 
									
										
										
										
											2016-10-23 14:30:32 +02:00
										 |  |  |       -> { Hbc::Artifact::App.new(cask).install_phase } | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let(:source_path) { cask.staged_path.join("Caffeine.app") } | 
					
						
							|  |  |  |     let(:target_path) { Hbc.appdir.join("AnotherName.app") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     before do | 
					
						
							| 
									
										
										
										
											2017-02-08 13:57:11 +01:00
										 |  |  |       InstallHelper.install_without_artifacts(cask) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "installs the given apps using the proper target directory" do | 
					
						
							| 
									
										
										
										
											2017-02-08 13:57:11 +01:00
										 |  |  |       expect(source_path).to be_a_directory | 
					
						
							|  |  |  |       expect(target_path).not_to exist | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |       install_phase.call | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 13:57:11 +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", target: "AnotherName.app" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  |       it "installs the given apps 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.call | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 13:57:11 +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.call | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 13:57:11 +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 13:57:11 +01:00
										 |  |  |       expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist | 
					
						
							|  |  |  |       expect(cask.staged_path.join("Caffeine Deluxe.app")).to be_a_directory | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "avoids clobbering an existing app by moving over it" do | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  |       target_path.mkpath | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 13:57:11 +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 13:57:11 +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
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |