| 
									
										
										
										
											2017-03-05 19:26:56 +01:00
										 |  |  | describe Hbc::Artifact::Artifact, :cask do | 
					
						
							| 
									
										
										
										
											2017-10-07 15:58:49 +02:00
										 |  |  |   let(:cask) { Hbc::CaskLoader.load(cask_path("with-generic-artifact")) } | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   let(:install_phase) { | 
					
						
							| 
									
										
										
										
											2017-10-04 17:54:52 +02:00
										 |  |  |     lambda do | 
					
						
							|  |  |  |       cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| | 
					
						
							|  |  |  |         artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  |   let(:source_path) { cask.staged_path.join("Caffeine.app") } | 
					
						
							| 
									
										
										
										
											2017-12-03 09:06:23 +01:00
										 |  |  |   let(:target_path) { Hbc::Config.global.appdir.join("Caffeine.app") } | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   before do | 
					
						
							| 
									
										
										
										
											2017-02-08 14:25:50 +01:00
										 |  |  |     InstallHelper.install_without_artifacts(cask) | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |   context "without target" do | 
					
						
							|  |  |  |     it "fails to load" do | 
					
						
							|  |  |  |       expect { | 
					
						
							| 
									
										
										
										
											2017-10-07 15:58:49 +02:00
										 |  |  |         Hbc::CaskLoader.load(cask_path("with-generic-artifact-no-target")) | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |       }.to raise_error(Hbc::CaskInvalidError, /target required for Generic Artifact/) | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "moves the artifact to the proper directory" do | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |     install_phase.call | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 14:25:50 +01:00
										 |  |  |     expect(target_path).to be_a_directory | 
					
						
							|  |  |  |     expect(source_path).not_to exist | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "avoids clobbering an existing artifact" do | 
					
						
							| 
									
										
										
										
											2016-10-19 16:42:31 -04:00
										 |  |  |     target_path.mkpath | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 14:25:50 +01:00
										 |  |  |     expect { | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |       install_phase.call | 
					
						
							| 
									
										
										
										
											2017-02-08 14:25:50 +01:00
										 |  |  |     }.to raise_error(Hbc::CaskError) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 14:25:50 +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 |