| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  | require_relative "shared_examples/invalid_option" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 19:26:56 +01:00
										 |  |  | describe Hbc::CLI::Audit, :cask do | 
					
						
							| 
									
										
										
										
											2017-09-11 08:37:15 +02:00
										 |  |  |   let(:cask) { Hbc::Cask.new(nil) } | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  |   it_behaves_like "a command that handles invalid options" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  |   describe "selection of Casks to audit" do | 
					
						
							|  |  |  |     it "audits all Casks if no tokens are given" do | 
					
						
							| 
									
										
										
										
											2017-09-11 08:37:15 +02:00
										 |  |  |       expect(cask).to be_a Hbc::Cask | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  |       allow(Hbc).to receive(:all).and_return([cask, cask]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |       expect(Hbc::Auditor).to receive(:audit).twice.and_return(true) | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  |       described_class.run | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "audits specified Casks if tokens are given" do | 
					
						
							|  |  |  |       cask_token = "nice-app" | 
					
						
							| 
									
										
										
										
											2017-03-13 01:09:36 +01:00
										 |  |  |       expect(Hbc::CaskLoader).to receive(:load).with(cask_token).and_return(cask) | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |       expect(Hbc::Auditor).to receive(:audit) | 
					
						
							| 
									
										
										
										
											2017-05-19 21:07:25 +02:00
										 |  |  |         .with(cask, audit_download: false, check_token_conflicts: false) | 
					
						
							|  |  |  |         .and_return(true) | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  |       described_class.run(cask_token) | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "rules for downloading a Cask" do | 
					
						
							|  |  |  |     it "does not download the Cask per default" do | 
					
						
							| 
									
										
										
										
											2017-03-13 01:09:36 +01:00
										 |  |  |       allow(Hbc::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |       expect(Hbc::Auditor).to receive(:audit) | 
					
						
							| 
									
										
										
										
											2017-05-19 21:07:25 +02:00
										 |  |  |         .with(cask, audit_download: false, check_token_conflicts: false) | 
					
						
							|  |  |  |         .and_return(true) | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  |       described_class.run("casktoken") | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "download a Cask if --download flag is set" do | 
					
						
							| 
									
										
										
										
											2017-03-13 01:09:36 +01:00
										 |  |  |       allow(Hbc::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |       expect(Hbc::Auditor).to receive(:audit) | 
					
						
							| 
									
										
										
										
											2017-05-19 21:07:25 +02:00
										 |  |  |         .with(cask, audit_download: true, check_token_conflicts: false) | 
					
						
							|  |  |  |         .and_return(true) | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  |       described_class.run("casktoken", "--download") | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "rules for checking token conflicts" do | 
					
						
							|  |  |  |     it "does not check for token conflicts per default" do | 
					
						
							| 
									
										
										
										
											2017-03-13 01:09:36 +01:00
										 |  |  |       allow(Hbc::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |       expect(Hbc::Auditor).to receive(:audit) | 
					
						
							| 
									
										
										
										
											2017-05-19 21:07:25 +02:00
										 |  |  |         .with(cask, audit_download: false, check_token_conflicts: false) | 
					
						
							|  |  |  |         .and_return(true) | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  |       described_class.run("casktoken") | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "checks for token conflicts if --token-conflicts flag is set" do | 
					
						
							| 
									
										
										
										
											2017-03-13 01:09:36 +01:00
										 |  |  |       allow(Hbc::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							| 
									
										
										
										
											2017-05-21 02:32:46 +02:00
										 |  |  |       expect(Hbc::Auditor).to receive(:audit) | 
					
						
							| 
									
										
										
										
											2017-05-19 21:07:25 +02:00
										 |  |  |         .with(cask, audit_download: false, check_token_conflicts: true) | 
					
						
							|  |  |  |         .and_return(true) | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  |       described_class.run("casktoken", "--token-conflicts") | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |