| 
									
										
										
										
											2017-03-05 19:26:56 +01:00
										 |  |  | describe Hbc::Audit, :cask do | 
					
						
							| 
									
										
										
										
											2017-03-05 03:46:13 +01:00
										 |  |  |   def include_msg?(messages, msg) | 
					
						
							|  |  |  |     if msg.is_a?(Regexp) | 
					
						
							|  |  |  |       Array(messages).any? { |m| m =~ msg } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       Array(messages).include?(msg) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   matcher :pass do | 
					
						
							|  |  |  |     match do |audit| | 
					
						
							|  |  |  |       !audit.errors? && !audit.warnings? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   matcher :fail do | 
					
						
							|  |  |  |     match(&:errors?) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   matcher :warn do | 
					
						
							|  |  |  |     match do |audit| | 
					
						
							|  |  |  |       audit.warnings? && !audit.errors? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   matcher :fail_with do |error_msg| | 
					
						
							|  |  |  |     match do |audit| | 
					
						
							|  |  |  |       include_msg?(audit.errors, error_msg) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   matcher :warn_with do |warning_msg| | 
					
						
							|  |  |  |     match do |audit| | 
					
						
							|  |  |  |       include_msg?(audit.warnings, warning_msg) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   let(:cask) { instance_double(Hbc::Cask) } | 
					
						
							|  |  |  |   let(:download) { false } | 
					
						
							|  |  |  |   let(:check_token_conflicts) { false } | 
					
						
							|  |  |  |   let(:fake_system_command) { class_double(Hbc::SystemCommand) } | 
					
						
							|  |  |  |   let(:audit) { | 
					
						
							|  |  |  |     Hbc::Audit.new(cask, download:              download, | 
					
						
							|  |  |  |                          check_token_conflicts: check_token_conflicts, | 
					
						
							|  |  |  |                          command:               fake_system_command) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#result" do | 
					
						
							|  |  |  |     subject { audit.result } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when there are errors" do | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         audit.add_error "bad" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |       it { is_expected.to match(/failed/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when there are warnings" do | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         audit.add_warning "eh" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |       it { is_expected.to match(/warning/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when there are errors and warnings" do | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         audit.add_error "bad" | 
					
						
							|  |  |  |         audit.add_warning "eh" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |       it { is_expected.to match(/failed/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when there are no errors or warnings" do | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |       it { is_expected.to match(/passed/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#run!" do | 
					
						
							| 
									
										
										
										
											2017-03-13 01:09:36 +01:00
										 |  |  |     let(:cask) { Hbc::CaskLoader.load(cask_token) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     subject { audit.run! } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "required stanzas" do | 
					
						
							| 
									
										
										
										
											2016-10-06 21:27:44 +08:00
										 |  |  |       %w[version sha256 url name homepage].each do |stanza| | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         context "when missing #{stanza}" do | 
					
						
							|  |  |  |           let(:cask_token) { "missing-#{stanza}" } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |           it { is_expected.to fail_with(/#{stanza} stanza is required/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "version checks" do | 
					
						
							|  |  |  |       let(:error_msg) { "you should use version :latest instead of version 'latest'" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when version is 'latest'" do | 
					
						
							|  |  |  |         let(:cask_token) { "version-latest-string" } | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |         it { is_expected.to fail_with(error_msg) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when version is :latest" do | 
					
						
							|  |  |  |         let(:cask_token) { "version-latest-with-checksum" } | 
					
						
							|  |  |  |         it { should_not fail_with(error_msg) } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "sha256 checks" do | 
					
						
							|  |  |  |       context "when version is :latest and sha256 is not :no_check" do | 
					
						
							|  |  |  |         let(:cask_token) { "version-latest-with-checksum" } | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |         it { is_expected.to fail_with("you should use sha256 :no_check when version is :latest") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when sha256 is not a legal SHA-256 digest" do | 
					
						
							|  |  |  |         let(:cask_token) { "invalid-sha256" } | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |         it { is_expected.to fail_with("sha256 string must be of 64 hexadecimal characters") } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when sha256 is sha256 for empty string" do | 
					
						
							|  |  |  |         let(:cask_token) { "sha256-for-empty-string" } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { is_expected.to fail_with(/cannot use the sha256 for an empty string/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "appcast checks" do | 
					
						
							|  |  |  |       context "when appcast has no sha256" do | 
					
						
							|  |  |  |         let(:cask_token) { "appcast-missing-checkpoint" } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { is_expected.to fail_with(/checkpoint sha256 is required for appcast/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when appcast checkpoint is not a string of 64 hexadecimal characters" do | 
					
						
							|  |  |  |         let(:cask_token) { "appcast-invalid-checkpoint" } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { is_expected.to fail_with(/string must be of 64 hexadecimal characters/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when appcast checkpoint is sha256 for empty string" do | 
					
						
							|  |  |  |         let(:cask_token) { "appcast-checkpoint-sha256-for-empty-string" } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { is_expected.to fail_with(/cannot use the sha256 for an empty string/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when appcast checkpoint is valid sha256" do | 
					
						
							|  |  |  |         let(:cask_token) { "appcast-valid-checkpoint" } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { should_not fail_with(/appcast :checkpoint/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when verifying appcast HTTP code" do | 
					
						
							|  |  |  |         let(:cask_token) { "appcast-valid-checkpoint" } | 
					
						
							|  |  |  |         let(:download) { instance_double(Hbc::Download) } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         let(:wrong_code_msg) { /unexpected HTTP response code/ } | 
					
						
							|  |  |  |         let(:curl_error_msg) { /error retrieving appcast/ } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         let(:fake_curl_result) { instance_double(Hbc::SystemCommand::Result) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         before do | 
					
						
							|  |  |  |           allow(audit).to receive(:check_appcast_checkpoint_accuracy) | 
					
						
							|  |  |  |           allow(fake_system_command).to receive(:run).and_return(fake_curl_result) | 
					
						
							|  |  |  |           allow(fake_curl_result).to receive(:success?).and_return(success) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         context "when curl succeeds" do | 
					
						
							|  |  |  |           let(:success) { true } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           before do | 
					
						
							|  |  |  |             allow(fake_curl_result).to receive(:stdout).and_return(stdout) | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           context "when HTTP code is 200" do | 
					
						
							|  |  |  |             let(:stdout) { "200" } | 
					
						
							|  |  |  |             it { should_not warn_with(wrong_code_msg) } | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           context "when HTTP code is not 200" do | 
					
						
							|  |  |  |             let(:stdout) { "404" } | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |             it { is_expected.to warn_with(wrong_code_msg) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         context "when curl fails" do | 
					
						
							|  |  |  |           let(:success) { false } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           before do | 
					
						
							|  |  |  |             allow(fake_curl_result).to receive(:stderr).and_return("Some curl error") | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |           it { is_expected.to warn_with(curl_error_msg) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when verifying appcast checkpoint" do | 
					
						
							|  |  |  |         let(:cask_token) { "appcast-valid-checkpoint" } | 
					
						
							|  |  |  |         let(:download) { instance_double(Hbc::Download) } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         let(:mismatch_msg) { /appcast checkpoint mismatch/ } | 
					
						
							|  |  |  |         let(:curl_error_msg) { /error retrieving appcast/ } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         let(:fake_curl_result) { instance_double(Hbc::SystemCommand::Result) } | 
					
						
							|  |  |  |         let(:expected_checkpoint) { "d5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         before do | 
					
						
							|  |  |  |           allow(audit).to receive(:check_appcast_http_code) | 
					
						
							| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  |           allow(Hbc::SystemCommand).to receive(:run).and_return(fake_curl_result) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           allow(fake_curl_result).to receive(:success?).and_return(success) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         context "when appcast download succeeds" do | 
					
						
							|  |  |  |           let(:success) { true } | 
					
						
							|  |  |  |           let(:appcast_text) { instance_double(::String) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           before do | 
					
						
							|  |  |  |             allow(fake_curl_result).to receive(:stdout).and_return(appcast_text) | 
					
						
							|  |  |  |             allow(appcast_text).to receive(:gsub).and_return(appcast_text) | 
					
						
							|  |  |  |             allow(appcast_text).to receive(:end_with?).with("\n").and_return(true) | 
					
						
							|  |  |  |             allow(Digest::SHA2).to receive(:hexdigest).and_return(actual_checkpoint) | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           context "when appcast checkpoint is out of date" do | 
					
						
							| 
									
										
										
										
											2017-02-08 07:24:41 +01:00
										 |  |  |             let(:actual_checkpoint) { "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" } | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |             it { is_expected.to warn_with(mismatch_msg) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |             it { should_not warn_with(curl_error_msg) } | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           context "when appcast checkpoint is up to date" do | 
					
						
							|  |  |  |             let(:actual_checkpoint) { expected_checkpoint } | 
					
						
							|  |  |  |             it { should_not warn_with(mismatch_msg) } | 
					
						
							|  |  |  |             it { should_not warn_with(curl_error_msg) } | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         context "when appcast download fails" do | 
					
						
							|  |  |  |           let(:success) { false } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           before do | 
					
						
							|  |  |  |             allow(fake_curl_result).to receive(:stderr).and_return("Some curl error") | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |           it { is_expected.to warn_with(curl_error_msg) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "preferred download URL formats" do | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |       let(:warning_msg) { /URL format incorrect/ } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       context "with incorrect SourceForge URL format" do | 
					
						
							|  |  |  |         let(:cask_token) { "sourceforge-incorrect-url-format" } | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |         it { is_expected.to warn_with(warning_msg) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with correct SourceForge URL format" do | 
					
						
							|  |  |  |         let(:cask_token) { "sourceforge-correct-url-format" } | 
					
						
							|  |  |  |         it { should_not warn_with(warning_msg) } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with correct SourceForge URL format for version :latest" do | 
					
						
							|  |  |  |         let(:cask_token) { "sourceforge-version-latest-correct-url-format" } | 
					
						
							|  |  |  |         it { should_not warn_with(warning_msg) } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with incorrect OSDN URL format" do | 
					
						
							|  |  |  |         let(:cask_token) { "osdn-incorrect-url-format" } | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |         it { is_expected.to warn_with(warning_msg) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with correct OSDN URL format" do | 
					
						
							|  |  |  |         let(:cask_token) { "osdn-correct-url-format" } | 
					
						
							|  |  |  |         it { should_not warn_with(warning_msg) } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "generic artifact checks" do | 
					
						
							|  |  |  |       context "with no target" do | 
					
						
							|  |  |  |         let(:cask_token) { "generic-artifact-no-target" } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { is_expected.to fail_with(/target required for generic artifact/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with relative target" do | 
					
						
							|  |  |  |         let(:cask_token) { "generic-artifact-relative-target" } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { is_expected.to fail_with(/target must be absolute path for generic artifact/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with absolute target" do | 
					
						
							|  |  |  |         let(:cask_token) { "generic-artifact-absolute-target" } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { should_not fail_with(/target required for generic artifact/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "url checks" do | 
					
						
							|  |  |  |       context "given a block" do | 
					
						
							|  |  |  |         let(:cask_token) { "booby-trap" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         context "when loading the cask" do | 
					
						
							|  |  |  |           it "does not evaluate the block" do | 
					
						
							| 
									
										
										
										
											2016-08-27 11:52:14 +02:00
										 |  |  |             expect { cask }.not_to raise_error | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         context "when doing the audit" do | 
					
						
							|  |  |  |           it "evaluates the block" do | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |             expect(subject).to fail_with(/Boom/) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "token conflicts" do | 
					
						
							|  |  |  |       let(:cask_token) { "with-binary" } | 
					
						
							|  |  |  |       let(:check_token_conflicts) { true } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         expect(audit).to receive(:core_formula_names).and_return(formula_names) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token conflicts with a core formula" do | 
					
						
							|  |  |  |         let(:formula_names) { %w[with-binary other-formula] } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { is_expected.to warn_with(/possible duplicate/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token does not conflict with a core formula" do | 
					
						
							|  |  |  |         let(:formula_names) { %w[other-formula] } | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { should_not warn_with(/possible duplicate/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "audit of downloads" do | 
					
						
							|  |  |  |       let(:cask_token) { "with-binary" } | 
					
						
							| 
									
										
										
										
											2017-03-13 01:09:36 +01:00
										 |  |  |       let(:cask) { Hbc::CaskLoader.load(cask_token) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       let(:download) { instance_double(Hbc::Download) } | 
					
						
							|  |  |  |       let(:verify) { class_double(Hbc::Verify).as_stubbed_const } | 
					
						
							|  |  |  |       let(:error_msg) { "Download Failed" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when download and verification succeed" do | 
					
						
							|  |  |  |         before do | 
					
						
							| 
									
										
										
										
											2016-10-19 23:01:52 +02:00
										 |  |  |           expect(download).to receive(:perform) | 
					
						
							|  |  |  |           expect(verify).to receive(:all) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { should_not fail_with(/#{error_msg}/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when download fails" do | 
					
						
							|  |  |  |         before do | 
					
						
							| 
									
										
										
										
											2016-10-19 23:01:52 +02:00
										 |  |  |           expect(download).to receive(:perform).and_raise(StandardError.new(error_msg)) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { is_expected.to fail_with(/#{error_msg}/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when verification fails" do | 
					
						
							|  |  |  |         before do | 
					
						
							| 
									
										
										
										
											2016-10-19 23:01:52 +02:00
										 |  |  |           expect(download).to receive(:perform) | 
					
						
							|  |  |  |           expect(verify).to receive(:all).and_raise(StandardError.new(error_msg)) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |         it { is_expected.to fail_with(/#{error_msg}/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when an exception is raised" do | 
					
						
							|  |  |  |       let(:cask) { instance_double(Hbc::Cask) } | 
					
						
							|  |  |  |       before do | 
					
						
							| 
									
										
										
										
											2016-10-19 23:01:52 +02:00
										 |  |  |         expect(cask).to receive(:version).and_raise(StandardError.new) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |       it { is_expected.to fail_with(/exception while auditing/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |