| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 10:49:58 +02:00
										 |  |  | require_relative "shared_examples/invalid_option" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  | describe Cask::Cmd::Audit, :cask do | 
					
						
							| 
									
										
										
										
											2019-02-03 13:03:16 +01:00
										 |  |  |   let(:cask) { Cask::Cask.new("cask") } | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |   let(:result) { { warnings: Set.new, errors: Set.new } } | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       allow(Cask::Cask).to receive(:to_a).and_return([cask, cask]) | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |       expect(Cask::Auditor).to receive(:audit).twice.and_return(result) | 
					
						
							| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::CaskLoader).to receive(:load).with(cask_token).and_return(cask) | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |         .with(cask, audit_download:        false, | 
					
						
							|  |  |  |                     audit_appcast:         false, | 
					
						
							|  |  |  |                     audit_token_conflicts: false, | 
					
						
							|  |  |  |                     audit_new_cask:        false, | 
					
						
							|  |  |  |                     audit_online:          false, | 
					
						
							|  |  |  |                     audit_strict:          false, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       allow(Cask::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							|  |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |         .with(cask, audit_download:        false, | 
					
						
							|  |  |  |                     audit_appcast:         false, | 
					
						
							|  |  |  |                     audit_token_conflicts: false, | 
					
						
							|  |  |  |                     audit_new_cask:        false, | 
					
						
							|  |  |  |                     audit_online:          false, | 
					
						
							|  |  |  |                     audit_strict:          false, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       allow(Cask::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							|  |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |         .with(cask, audit_download:        true, | 
					
						
							|  |  |  |                     audit_appcast:         false, | 
					
						
							|  |  |  |                     audit_token_conflicts: false, | 
					
						
							|  |  |  |                     audit_new_cask:        false, | 
					
						
							|  |  |  |                     audit_online:          false, | 
					
						
							|  |  |  |                     audit_strict:          false, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       allow(Cask::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							|  |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |         .with(cask, audit_download:        false, | 
					
						
							|  |  |  |                     audit_appcast:         false, | 
					
						
							|  |  |  |                     audit_token_conflicts: false, | 
					
						
							|  |  |  |                     audit_new_cask:        false, | 
					
						
							|  |  |  |                     audit_online:          false, | 
					
						
							|  |  |  |                     audit_strict:          false, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       allow(Cask::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							|  |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  |         .with(cask, audit_download:        false, | 
					
						
							|  |  |  |                     audit_appcast:         false, | 
					
						
							|  |  |  |                     audit_token_conflicts: true, | 
					
						
							|  |  |  |                     audit_new_cask:        false, | 
					
						
							|  |  |  |                     audit_online:          false, | 
					
						
							|  |  |  |                     audit_strict:          false, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "rules for checking strictly" do | 
					
						
							|  |  |  |     it "does not check strictly per default" do | 
					
						
							|  |  |  |       allow(Cask::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							|  |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							|  |  |  |         .with(cask, audit_download:        false, | 
					
						
							|  |  |  |                     audit_appcast:         false, | 
					
						
							|  |  |  |                     audit_token_conflicts: false, | 
					
						
							|  |  |  |                     audit_new_cask:        false, | 
					
						
							|  |  |  |                     audit_online:          false, | 
					
						
							|  |  |  |                     audit_strict:          false, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       described_class.run("casktoken") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "checks strictly if --strict flag is set" do | 
					
						
							|  |  |  |       allow(Cask::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							|  |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							|  |  |  |         .with(cask, audit_download:        false, | 
					
						
							|  |  |  |                     audit_appcast:         false, | 
					
						
							|  |  |  |                     audit_token_conflicts: true, | 
					
						
							|  |  |  |                     audit_new_cask:        false, | 
					
						
							|  |  |  |                     audit_online:          false, | 
					
						
							|  |  |  |                     audit_strict:          true, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       described_class.run("casktoken", "--strict") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "rules for checking online" do | 
					
						
							|  |  |  |     it "does not check online per default" do | 
					
						
							|  |  |  |       allow(Cask::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							|  |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							|  |  |  |         .with(cask, audit_download:        false, | 
					
						
							|  |  |  |                     audit_appcast:         false, | 
					
						
							|  |  |  |                     audit_token_conflicts: false, | 
					
						
							|  |  |  |                     audit_new_cask:        false, | 
					
						
							|  |  |  |                     audit_online:          false, | 
					
						
							|  |  |  |                     audit_strict:          false, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       described_class.run("casktoken") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "checks online if --online flag is set" do | 
					
						
							|  |  |  |       allow(Cask::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							|  |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							|  |  |  |         .with(cask, audit_download:        true, | 
					
						
							|  |  |  |                     audit_appcast:         true, | 
					
						
							|  |  |  |                     audit_token_conflicts: false, | 
					
						
							|  |  |  |                     audit_new_cask:        false, | 
					
						
							|  |  |  |                     audit_online:          true, | 
					
						
							|  |  |  |                     audit_strict:          false, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       described_class.run("casktoken", "--online") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "rules for checking new casks" do | 
					
						
							|  |  |  |     it "does not check new casks per default" do | 
					
						
							|  |  |  |       allow(Cask::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							|  |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							|  |  |  |         .with(cask, audit_download:        false, | 
					
						
							|  |  |  |                     audit_appcast:         false, | 
					
						
							|  |  |  |                     audit_token_conflicts: false, | 
					
						
							|  |  |  |                     audit_new_cask:        false, | 
					
						
							|  |  |  |                     audit_online:          false, | 
					
						
							|  |  |  |                     audit_strict:          false, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       described_class.run("casktoken") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "checks new casks if --new-cask flag is set" do | 
					
						
							|  |  |  |       allow(Cask::CaskLoader).to receive(:load).and_return(cask) | 
					
						
							|  |  |  |       expect(Cask::Auditor).to receive(:audit) | 
					
						
							|  |  |  |         .with(cask, audit_download:        true, | 
					
						
							|  |  |  |                     audit_appcast:         true, | 
					
						
							|  |  |  |                     audit_token_conflicts: true, | 
					
						
							|  |  |  |                     audit_new_cask:        true, | 
					
						
							|  |  |  |                     audit_online:          true, | 
					
						
							|  |  |  |                     audit_strict:          true, | 
					
						
							|  |  |  |                     quarantine:            true) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:08:37 +02:00
										 |  |  |         .and_return(result) | 
					
						
							| 
									
										
										
										
											2020-04-23 21:16:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       described_class.run("casktoken", "--new-cask") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-02-08 11:58:34 +01:00
										 |  |  | end |