| 
									
										
										
										
											2017-03-05 19:26:56 +01:00
										 |  |  | describe Hbc::Artifact::Binary, :cask do | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   let(:cask) { | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |     Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-binary.rb").tap do |cask| | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       shutup do | 
					
						
							|  |  |  |         InstallHelper.install_without_artifacts(cask) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-04-21 14:50:23 +02:00
										 |  |  |   let(:expected_path) { Hbc.binarydir.join("binary") } | 
					
						
							| 
									
										
										
										
											2017-03-08 16:35:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   before(:each) do | 
					
						
							|  |  |  |     Hbc.binarydir.mkpath | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-03-08 16:35:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   after(:each) do | 
					
						
							|  |  |  |     FileUtils.rm expected_path if expected_path.exist? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "links the binary to the proper directory" do | 
					
						
							|  |  |  |     shutup do | 
					
						
							|  |  |  |       Hbc::Artifact::Binary.new(cask).install_phase | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-09 19:01:46 +01:00
										 |  |  |     expect(expected_path).to be_a_symlink | 
					
						
							|  |  |  |     expect(expected_path.readlink).to exist | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 14:50:23 +02:00
										 |  |  |   context "when the binary is not executable" do | 
					
						
							|  |  |  |     let(:cask) { | 
					
						
							|  |  |  |       Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-non-executable-binary.rb").tap do |cask| | 
					
						
							|  |  |  |         shutup do | 
					
						
							|  |  |  |           InstallHelper.install_without_artifacts(cask) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-08 16:35:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 14:50:23 +02:00
										 |  |  |     let(:expected_path) { Hbc.binarydir.join("naked_non_executable") } | 
					
						
							| 
									
										
										
										
											2017-03-08 16:35:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 14:50:23 +02:00
										 |  |  |     it "makes the binary executable" do | 
					
						
							|  |  |  |       expect(FileUtils).to receive(:chmod) | 
					
						
							|  |  |  |         .with("+x", cask.staged_path.join("naked_non_executable")).and_call_original | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       shutup do | 
					
						
							|  |  |  |         Hbc::Artifact::Binary.new(cask).install_phase | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(expected_path).to be_a_symlink | 
					
						
							|  |  |  |       expect(expected_path.readlink).to be_executable | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-03-08 16:35:02 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   it "avoids clobbering an existing binary by linking over it" do | 
					
						
							|  |  |  |     FileUtils.touch expected_path | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-29 11:04:45 +01:00
										 |  |  |     expect { | 
					
						
							|  |  |  |       shutup do | 
					
						
							|  |  |  |         Hbc::Artifact::Binary.new(cask).install_phase | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     }.to raise_error(Hbc::CaskError) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |     expect(expected_path).not_to be :symlink? | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "clobbers an existing symlink" do | 
					
						
							|  |  |  |     expected_path.make_symlink("/tmp") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     shutup do | 
					
						
							|  |  |  |       Hbc::Artifact::Binary.new(cask).install_phase | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(File.readlink(expected_path)).not_to eq("/tmp") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "respects --no-binaries flag" do | 
					
						
							| 
									
										
										
										
											2017-03-06 20:37:13 +01:00
										 |  |  |     begin | 
					
						
							|  |  |  |       Hbc::CLI.binaries = false | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-06 20:37:13 +01:00
										 |  |  |       expect(Hbc::CLI).not_to be_binaries | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-06 20:37:13 +01:00
										 |  |  |       shutup do | 
					
						
							|  |  |  |         Hbc::Artifact::Binary.new(cask).install_phase | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-06 20:37:13 +01:00
										 |  |  |       expect(expected_path.exist?).to be false | 
					
						
							|  |  |  |     ensure | 
					
						
							|  |  |  |       Hbc::CLI.binaries = true | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "creates parent directory if it doesn't exist" do | 
					
						
							|  |  |  |     FileUtils.rmdir Hbc.binarydir | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     shutup do | 
					
						
							|  |  |  |       Hbc::Artifact::Binary.new(cask).install_phase | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(expected_path.exist?).to be true | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   context "binary is inside an app package" do | 
					
						
							|  |  |  |     let(:cask) { | 
					
						
							| 
									
										
										
										
											2016-12-06 16:36:34 +01:00
										 |  |  |       Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-embedded-binary.rb").tap do |cask| | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         shutup do | 
					
						
							|  |  |  |           InstallHelper.install_without_artifacts(cask) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "links the binary to the proper directory" do | 
					
						
							|  |  |  |       shutup do | 
					
						
							|  |  |  |         Hbc::Artifact::App.new(cask).install_phase | 
					
						
							|  |  |  |         Hbc::Artifact::Binary.new(cask).install_phase | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 19:01:46 +01:00
										 |  |  |       expect(expected_path).to be_a_symlink | 
					
						
							|  |  |  |       expect(expected_path.readlink).to exist | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |