| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-09 01:34:07 +02:00
										 |  |  | require "cask/audit" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe Cask::Audit, :cask do | 
					
						
							| 
									
										
										
										
											2021-04-03 03:49:41 +02:00
										 |  |  |   def include_msg?(problems, msg) | 
					
						
							| 
									
										
										
										
											2017-03-05 03:46:13 +01:00
										 |  |  |     if msg.is_a?(Regexp) | 
					
						
							| 
									
										
										
										
											2023-12-27 15:29:33 -08:00
										 |  |  |       Array(problems).any? { |problem| msg.match?(problem[:message]) } | 
					
						
							| 
									
										
										
										
											2017-03-05 03:46:13 +01:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2021-04-03 03:49:41 +02:00
										 |  |  |       Array(problems).any? { |problem| problem[:message] == msg } | 
					
						
							| 
									
										
										
										
											2017-03-05 03:46:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |   def passed?(audit) | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |     !audit.errors? | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def outcome(audit) | 
					
						
							|  |  |  |     if passed?(audit) | 
					
						
							|  |  |  |       "passed" | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |       "errored with #{audit.errors.map { |e| e.fetch(:message).inspect }.join(",")}" | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 03:46:13 +01:00
										 |  |  |   matcher :pass do | 
					
						
							|  |  |  |     match do |audit| | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |       passed?(audit) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     failure_message do |audit| | 
					
						
							|  |  |  |       "expected to pass, but #{outcome(audit)}" | 
					
						
							| 
									
										
										
										
											2017-03-05 03:46:13 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |   matcher :error_with do |message| | 
					
						
							| 
									
										
										
										
											2017-03-05 03:46:13 +01:00
										 |  |  |     match do |audit| | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       include_msg?(audit.errors, message) | 
					
						
							| 
									
										
										
										
											2017-03-05 03:46:13 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     failure_message do |audit| | 
					
						
							|  |  |  |       "expected to error with message #{message.inspect} but #{outcome(audit)}" | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-03-05 03:46:13 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |   let(:cask) { instance_double(Cask::Cask) } | 
					
						
							| 
									
										
										
										
											2020-09-04 05:29:56 +02:00
										 |  |  |   let(:new_cask) { nil } | 
					
						
							|  |  |  |   let(:online) { nil } | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |   let(:only) { [] } | 
					
						
							| 
									
										
										
										
											2023-02-05 15:22:06 +01:00
										 |  |  |   let(:except) { [] } | 
					
						
							| 
									
										
										
										
											2020-09-04 05:29:56 +02:00
										 |  |  |   let(:strict) { nil } | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |   let(:signing) { nil } | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |   let(:audit) do | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |     described_class.new(cask, online:, | 
					
						
							|  |  |  |                               strict:, | 
					
						
							|  |  |  |                               new_cask:, | 
					
						
							|  |  |  |                               signing:, | 
					
						
							|  |  |  |                               only:, | 
					
						
							|  |  |  |                               except:) | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 05:29:56 +02:00
										 |  |  |   describe "#new" do | 
					
						
							|  |  |  |     context "when `new_cask` is specified" do | 
					
						
							|  |  |  |       let(:new_cask) { true } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "implies `online`" do | 
					
						
							|  |  |  |         expect(audit).to be_online | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "implies `strict`" do | 
					
						
							|  |  |  |         expect(audit).to be_strict | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when `online` is specified" do | 
					
						
							|  |  |  |       let(:online) { true } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |       it "implies `download`" do | 
					
						
							|  |  |  |         expect(audit.download).to be_truthy | 
					
						
							| 
									
										
										
										
											2020-09-04 05:29:56 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when `signing` is specified" do | 
					
						
							|  |  |  |       let(:signing) { true } | 
					
						
							| 
									
										
										
										
											2020-09-04 05:29:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it "implies `download`" do | 
					
						
							|  |  |  |         expect(audit.download).to be_truthy | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   describe "#result" do | 
					
						
							|  |  |  |     subject { audit.result } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |     context "when there are no errors and `--strict` is not passed so we should not show anything" do | 
					
						
							|  |  |  |       before do | 
					
						
							| 
									
										
										
										
											2023-04-04 17:22:00 +01:00
										 |  |  |         audit.add_error("eh", strict_only: true) | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.not_to match(/failed/) } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |     context "when there are errors and warnings" do | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       before do | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |         audit.add_error "bad" | 
					
						
							| 
									
										
										
										
											2023-04-04 17:22:00 +01:00
										 |  |  |         audit.add_error("eh", strict_only: true) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |       it { is_expected.to match(/failed/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |     context "when there are errors and warnings and `--strict` is passed" do | 
					
						
							|  |  |  |       let(:strict) { true } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       before do | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |         audit.add_error "very bad" | 
					
						
							| 
									
										
										
										
											2023-04-04 17:22:00 +01:00
										 |  |  |         audit.add_error("a little bit bad", strict_only: true) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-14 20:03:34 +02:00
										 |  |  |       it { is_expected.to match(/failed/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |     context "when there are warnings and `--strict` is not passed" do | 
					
						
							|  |  |  |       before do | 
					
						
							| 
									
										
										
										
											2023-04-04 17:22:00 +01:00
										 |  |  |         audit.add_error("a little bit bad", strict_only: true) | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.not_to match(/failed/) } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when there are warnings and `--strict` is passed" do | 
					
						
							|  |  |  |       let(:strict) { true } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       before do | 
					
						
							| 
									
										
										
										
											2023-04-04 17:22:00 +01:00
										 |  |  |         audit.add_error("a little bit bad", strict_only: true) | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.to match(/failed/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#run!" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |     subject(:run) { audit.run! } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |     def tmp_cask(name, text) | 
					
						
							|  |  |  |       path = Pathname.new "#{dir}/#{name}.rb" | 
					
						
							|  |  |  |       path.open("w") do |f| | 
					
						
							|  |  |  |         f.write text | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       Cask::CaskLoader.load(path) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let(:dir) { mktmpdir } | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |     let(:cask) { Cask::CaskLoader.load(cask_token) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     describe "required stanzas" do | 
					
						
							| 
									
										
										
										
											2022-09-15 15:27:43 +02:00
										 |  |  |       let(:only) { ["required_stanzas"] } | 
					
						
							| 
									
										
										
										
											2022-09-15 15:33:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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}" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |           it { is_expected.to error_with(/#{stanza} stanza is required/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-03-25 15:30:16 +10:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |     describe "token validation" do | 
					
						
							|  |  |  |       let(:strict) { true } | 
					
						
							| 
									
										
										
										
											2024-06-25 22:08:48 +02:00
										 |  |  |       let(:only) { ["token"] } | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |       let(:cask) do | 
					
						
							|  |  |  |         tmp_cask cask_token.to_s, <<~RUBY | 
					
						
							|  |  |  |           cask '#{cask_token}' do | 
					
						
							|  |  |  |             version '1.0' | 
					
						
							|  |  |  |             sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a' | 
					
						
							|  |  |  |             url "https://brew.sh/" | 
					
						
							|  |  |  |             name 'Audit' | 
					
						
							|  |  |  |             homepage 'https://brew.sh/' | 
					
						
							|  |  |  |             app 'Audit.app' | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         RUBY | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token is not lowercase" do | 
					
						
							|  |  |  |         let(:cask_token) { "Upper-Case" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2024-06-25 22:08:48 +02:00
										 |  |  |           expect(run).to error_with(/not contain uppercase/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token is not ascii" do | 
					
						
							|  |  |  |         let(:cask_token) { "ascii⌘" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2024-06-25 22:08:48 +02:00
										 |  |  |           expect(run).to error_with(/not contain non-ASCII characters/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-09 11:32:16 -05:00
										 |  |  |       context "when cask token is @-versioned with number" do | 
					
						
							|  |  |  |         let(:cask_token) { "app@10" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "does not fail" do | 
					
						
							|  |  |  |           expect(run).to pass | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token is @-versioned with word" do | 
					
						
							|  |  |  |         let(:cask_token) { "app@beta" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "does not fail" do | 
					
						
							|  |  |  |           expect(run).to pass | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token has multiple @" do | 
					
						
							|  |  |  |         let(:cask_token) { "app@stuff@beta" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2024-06-25 22:08:48 +02:00
										 |  |  |           expect(run).to error_with(/not contain multiple @ symbols/) | 
					
						
							| 
									
										
										
										
											2024-03-09 11:32:16 -05:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token has a hyphen followed by @" do | 
					
						
							|  |  |  |         let(:cask_token) { "app-@beta" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2024-06-25 22:08:48 +02:00
										 |  |  |           expect(run).to error_with(/not contain a hyphen followed by an @/) | 
					
						
							| 
									
										
										
										
											2024-03-09 11:32:16 -05:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token has @ followed by a hyphen" do | 
					
						
							|  |  |  |         let(:cask_token) { "app@-beta" } | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2024-06-25 22:08:48 +02:00
										 |  |  |           expect(run).to error_with(/not contain an @ followed by a hyphen/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token has whitespace" do | 
					
						
							|  |  |  |         let(:cask_token) { "app stuff" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2024-06-25 22:08:48 +02:00
										 |  |  |           expect(run).to error_with(/not contain whitespace/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token has double hyphens" do | 
					
						
							|  |  |  |         let(:cask_token) { "app--stuff" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2024-06-25 22:08:48 +02:00
										 |  |  |           expect(run).to error_with(/not contain double hyphens/) | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token has leading hyphens" do | 
					
						
							|  |  |  |         let(:cask_token) { "-app" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2024-06-25 22:08:48 +02:00
										 |  |  |           expect(run).to error_with(/not contain a leading hyphen/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token has trailing hyphens" do | 
					
						
							|  |  |  |         let(:cask_token) { "app-" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2024-06-25 22:08:48 +02:00
										 |  |  |           expect(run).to error_with(/not contain a trailing hyphen/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "token bad words" do | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:new_cask) { true } | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["token_bad_words", "reverse_migration"] } | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:online) { false } | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |       let(:cask) do | 
					
						
							|  |  |  |         tmp_cask cask_token.to_s, <<~RUBY | 
					
						
							| 
									
										
										
										
											2020-12-11 21:58:09 +01:00
										 |  |  |           cask "#{cask_token}" do | 
					
						
							|  |  |  |             version "1.0" | 
					
						
							|  |  |  |             sha256 "8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a" | 
					
						
							|  |  |  |             url "https://brew.sh/v\#{version}.zip" | 
					
						
							|  |  |  |             name "Audit" | 
					
						
							|  |  |  |             desc "Cask for testing tokens" | 
					
						
							|  |  |  |             homepage "https://brew.sh/" | 
					
						
							|  |  |  |             app "Audit.app" | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |           end | 
					
						
							|  |  |  |         RUBY | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token contains .app" do | 
					
						
							|  |  |  |         let(:cask_token) { "token.app" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |           expect(run).to error_with(/token contains .app/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token contains launcher" do | 
					
						
							|  |  |  |         let(:cask_token) { "token-launcher" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |           expect(run).to error_with(/token mentions launcher/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token contains desktop" do | 
					
						
							|  |  |  |         let(:cask_token) { "token-desktop" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |           expect(run).to error_with(/token mentions desktop/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token contains platform" do | 
					
						
							|  |  |  |         let(:cask_token) { "token-osx" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |           expect(run).to error_with(/token mentions platform/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token contains architecture" do | 
					
						
							|  |  |  |         let(:cask_token) { "token-x86" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |           expect(run).to error_with(/token mentions architecture/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token contains framework" do | 
					
						
							|  |  |  |         let(:cask_token) { "token-java" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |           expect(run).to error_with(/cask token mentions framework/) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token is framework" do | 
					
						
							|  |  |  |         let(:cask_token) { "java" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "does not fail" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |           expect(run).to pass | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-01-26 01:16:00 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |       context "when cask token is in tap_migrations.json and" do | 
					
						
							| 
									
										
										
										
											2021-01-26 01:16:00 -08:00
										 |  |  |         let(:cask_token) { "token-migrated" } | 
					
						
							| 
									
										
										
										
											2023-12-13 13:17:12 +00:00
										 |  |  |         let(:tap) { CoreCaskTap.instance } | 
					
						
							| 
									
										
										
										
											2021-01-26 01:16:00 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         before do | 
					
						
							|  |  |  |           allow(tap).to receive(:tap_migrations).and_return({ cask_token => "homebrew/core" }) | 
					
						
							|  |  |  |           allow(cask).to receive(:tap).and_return(tap) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |         context "when `new_cask` is true" do | 
					
						
							| 
									
										
										
										
											2021-01-26 01:16:00 -08:00
										 |  |  |           let(:new_cask) { true } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           it "fails" do | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |             expect(run).to error_with("#{cask_token} is listed in tap_migrations.json") | 
					
						
							| 
									
										
										
										
											2021-01-26 01:16:00 -08:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |         context "when `new_cask` is false" do | 
					
						
							| 
									
										
										
										
											2021-01-26 01:16:00 -08:00
										 |  |  |           let(:new_cask) { false } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           it "does not fail" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |             expect(run).to pass | 
					
						
							| 
									
										
										
										
											2021-01-26 01:16:00 -08:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-06-04 23:11:51 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 23:37:54 +02:00
										 |  |  |     describe "locale validation" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["languages"] } | 
					
						
							| 
									
										
										
										
											2020-06-04 23:37:54 +02:00
										 |  |  |       let(:cask) do | 
					
						
							|  |  |  |         tmp_cask "locale-cask-test", <<~RUBY | 
					
						
							|  |  |  |           cask 'locale-cask-test' do | 
					
						
							|  |  |  |             version '1.0' | 
					
						
							|  |  |  |             url "https://brew.sh/" | 
					
						
							|  |  |  |             name 'Audit' | 
					
						
							|  |  |  |             homepage 'https://brew.sh/' | 
					
						
							|  |  |  |             app 'Audit.app' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             language 'en', default: true do | 
					
						
							|  |  |  |               sha256 '96574251b885c12b48a3495e843e434f9174e02bb83121b578e17d9dbebf1ffb' | 
					
						
							|  |  |  |               'zh-CN' | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             language 'zh-CN' do | 
					
						
							|  |  |  |               sha256 '96574251b885c12b48a3495e843e434f9174e02bb83121b578e17d9dbebf1ffb' | 
					
						
							|  |  |  |               'zh-CN' | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             language 'ZH-CN' do | 
					
						
							|  |  |  |               sha256 '96574251b885c12b48a3495e843e434f9174e02bb83121b578e17d9dbebf1ffb' | 
					
						
							|  |  |  |               'zh-CN' | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             language 'zh-' do | 
					
						
							|  |  |  |               sha256 '96574251b885c12b48a3495e843e434f9174e02bb83121b578e17d9dbebf1ffb' | 
					
						
							|  |  |  |               'zh-CN' | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             language 'zh-cn' do | 
					
						
							|  |  |  |               sha256 '96574251b885c12b48a3495e843e434f9174e02bb83121b578e17d9dbebf1ffb' | 
					
						
							|  |  |  |               'zh-CN' | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         RUBY | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask locale is invalid" do | 
					
						
							|  |  |  |         it "error with invalid locale" do | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |           expect(run).to error_with(/Locale 'ZH-CN' is invalid\./) | 
					
						
							|  |  |  |           expect(run).to error_with(/Locale 'zh-' is invalid\./) | 
					
						
							|  |  |  |           expect(run).to error_with(/Locale 'zh-cn' is invalid\./) | 
					
						
							| 
									
										
										
										
											2020-06-04 23:37:54 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 15:30:16 +10:00
										 |  |  |     describe "pkg allow_untrusted checks" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["untrusted_pkg"] } | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:message) { "allow_untrusted is not permitted in official Homebrew Cask taps" } | 
					
						
							| 
									
										
										
										
											2018-03-25 15:30:16 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |       context "when the Cask has no pkg stanza" do | 
					
						
							|  |  |  |         let(:cask_token) { "basic-cask" } | 
					
						
							| 
									
										
										
										
											2018-03-28 22:05:56 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-03-25 15:30:16 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when the Cask does not have allow_untrusted" do | 
					
						
							|  |  |  |         let(:cask_token) { "with-uninstall-pkgutil" } | 
					
						
							| 
									
										
										
										
											2018-03-28 22:05:56 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-03-25 15:30:16 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when the Cask has allow_untrusted" do | 
					
						
							|  |  |  |         let(:cask_token) { "with-allow-untrusted" } | 
					
						
							| 
									
										
										
										
											2018-03-28 22:05:56 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-03-25 15:30:16 +10:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-01 14:30:04 +02:00
										 |  |  |     describe "signing checks" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["signing"] } | 
					
						
							| 
									
										
										
										
											2022-08-01 14:30:04 +02:00
										 |  |  |       let(:download_double) { instance_double(Cask::Download) } | 
					
						
							|  |  |  |       let(:unpack_double) { instance_double(UnpackStrategy::Zip) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       before do | 
					
						
							| 
									
										
										
										
											2023-12-14 02:52:30 +00:00
										 |  |  |         allow(audit).to receive_messages(download: download_double, signing?: true) | 
					
						
							| 
									
										
										
										
											2022-08-01 14:30:04 +02:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask is not using a signed artifact" do | 
					
						
							|  |  |  |         let(:cask) do | 
					
						
							|  |  |  |           tmp_cask "signing-cask-test", <<~RUBY | 
					
						
							|  |  |  |             cask 'signing-cask-test' do | 
					
						
							|  |  |  |               version '1.0' | 
					
						
							|  |  |  |               url "https://brew.sh/index.html" | 
					
						
							| 
									
										
										
										
											2023-04-20 23:37:05 -07:00
										 |  |  |               artifact "example.pdf", target: "/Library/Application Support/example" | 
					
						
							| 
									
										
										
										
											2022-08-01 14:30:04 +02:00
										 |  |  |             end | 
					
						
							|  |  |  |           RUBY | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "does not fail" do | 
					
						
							|  |  |  |           expect(download_double).not_to receive(:fetch) | 
					
						
							|  |  |  |           expect(UnpackStrategy).not_to receive(:detect) | 
					
						
							| 
									
										
										
										
											2023-03-31 01:25:36 +01:00
										 |  |  |           expect(run).not_to error_with(/Audit\.app/) | 
					
						
							| 
									
										
										
										
											2022-08-01 14:30:04 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask is using a signed artifact" do | 
					
						
							|  |  |  |         let(:cask) do | 
					
						
							|  |  |  |           tmp_cask "signing-cask-test", <<~RUBY | 
					
						
							|  |  |  |             cask 'signing-cask-test' do | 
					
						
							|  |  |  |               version '1.0' | 
					
						
							|  |  |  |               url "https://brew.sh/" | 
					
						
							|  |  |  |               pkg 'Audit.app' | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           RUBY | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "does not fail since no extract" do | 
					
						
							|  |  |  |           allow(download_double).to receive(:fetch).and_return(Pathname.new("/tmp/test.zip")) | 
					
						
							|  |  |  |           allow(UnpackStrategy).to receive(:detect).and_return(nil) | 
					
						
							| 
									
										
										
										
											2023-03-31 01:25:36 +01:00
										 |  |  |           expect(run).not_to error_with(/Audit\.app/) | 
					
						
							| 
									
										
										
										
											2022-08-01 14:30:04 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-11 19:44:26 -04:00
										 |  |  |     describe "livecheck should be skipped", :no_api do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["livecheck_version"] } | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  |       let(:online) { true } | 
					
						
							|  |  |  |       let(:message) { /Version '[^']*' differs from '[^']*' retrieved by livecheck\./ } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-02 10:06:14 -05:00
										 |  |  |       context "when the Cask has a `livecheck` block using skip" do | 
					
						
							| 
									
										
										
										
											2024-02-09 23:17:25 +01:00
										 |  |  |         let(:cask_token) { "livecheck-skip" } | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-02 10:06:14 -05:00
										 |  |  |       context "when the Cask has a `livecheck` block referencing a Cask using skip" do | 
					
						
							| 
									
										
										
										
											2024-02-09 23:17:25 +01:00
										 |  |  |         let(:cask_token) { "livecheck-skip-reference" } | 
					
						
							| 
									
										
										
										
											2021-11-02 12:09:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2021-11-02 12:09:56 -04:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 20:37:01 -05:00
										 |  |  |       context "when the Cask is deprecated" do | 
					
						
							| 
									
										
										
										
											2024-02-09 23:17:25 +01:00
										 |  |  |         let(:cask_token) { "livecheck-deprecated" } | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-02 10:06:14 -05:00
										 |  |  |       context "when the Cask has a `livecheck` block referencing a deprecated Cask" do | 
					
						
							| 
									
										
										
										
											2024-02-09 23:17:25 +01:00
										 |  |  |         let(:cask_token) { "livecheck-deprecated-reference" } | 
					
						
							| 
									
										
										
										
											2023-12-16 20:37:01 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when the Cask is disabled" do | 
					
						
							| 
									
										
										
										
											2024-02-09 23:17:25 +01:00
										 |  |  |         let(:cask_token) { "livecheck-disabled" } | 
					
						
							| 
									
										
										
										
											2023-12-16 20:37:01 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-02 10:06:14 -05:00
										 |  |  |       context "when the Cask has a `livecheck` block referencing a disabled Cask" do | 
					
						
							| 
									
										
										
										
											2024-02-09 23:17:25 +01:00
										 |  |  |         let(:cask_token) { "livecheck-disabled-reference" } | 
					
						
							| 
									
										
										
										
											2021-11-02 12:09:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2021-11-02 12:09:56 -04:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  |       context "when version is :latest" do | 
					
						
							| 
									
										
										
										
											2024-02-09 23:17:25 +01:00
										 |  |  |         let(:cask_token) { "livecheck-version-latest" } | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-02 10:06:14 -05:00
										 |  |  |       context "when the Cask has a `livecheck` block referencing a Cask where version is :latest" do | 
					
						
							| 
									
										
										
										
											2024-02-09 23:17:25 +01:00
										 |  |  |         let(:cask_token) { "livecheck-version-latest-reference" } | 
					
						
							| 
									
										
										
										
											2021-11-02 12:09:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2021-11-02 12:09:56 -04:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  |       context "when url is unversioned" do | 
					
						
							| 
									
										
										
										
											2024-02-09 23:17:25 +01:00
										 |  |  |         let(:cask_token) { "livecheck-url-unversioned" } | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-11-02 12:09:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-02 10:06:14 -05:00
										 |  |  |       context "when the Cask has a `livecheck` block referencing a Cask with an unversioned url" do | 
					
						
							| 
									
										
										
										
											2024-02-09 23:17:25 +01:00
										 |  |  |         let(:cask_token) { "livecheck-url-unversioned-reference" } | 
					
						
							| 
									
										
										
										
											2021-11-02 12:09:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2021-11-02 12:09:56 -04:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-06-14 12:05:32 -04:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-19 12:38:47 +10:00
										 |  |  |     describe "when the Cask stanza requires uninstall" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["stanza_requires_uninstall"] } | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:message) { "installer and pkg stanzas require an uninstall stanza" } | 
					
						
							| 
									
										
										
										
											2018-05-19 12:38:47 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |       context "when the Cask does not require an uninstall" do | 
					
						
							|  |  |  |         let(:cask_token) { "basic-cask" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-05-19 12:38:47 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when the pkg Cask has an uninstall" do | 
					
						
							|  |  |  |         let(:cask_token) { "with-uninstall-pkgutil" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-05-19 12:38:47 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when the installer Cask has an uninstall" do | 
					
						
							|  |  |  |         let(:cask_token) { "installer-with-uninstall" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-05-19 12:38:47 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when the installer Cask does not have an uninstall" do | 
					
						
							|  |  |  |         let(:cask_token) { "with-installer-manual" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-05-19 12:38:47 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when the pkg Cask does not have an uninstall" do | 
					
						
							|  |  |  |         let(:cask_token) { "pkg-without-uninstall" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-05-19 12:38:47 +10:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |     describe "preflight stanza checks" do | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:message) { "only a single preflight stanza is allowed" } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has no preflight stanza" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-zap-rmdir" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has only one preflight stanza" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-preflight" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has multiple preflight stanzas" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-preflight-multi" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |     describe "postflight stanza checks" do | 
					
						
							|  |  |  |       let(:message) { "only a single postflight stanza is allowed" } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has no postflight stanza" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-zap-rmdir" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has only one postflight stanza" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-postflight" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has multiple postflight stanzas" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-postflight-multi" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "uninstall_preflight stanza checks" do | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:message) { "only a single uninstall_preflight stanza is allowed" } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has no uninstall_preflight stanza" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-zap-rmdir" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has only one uninstall_preflight stanza" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-uninstall-preflight" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has multiple uninstall_preflight stanzas" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-uninstall-preflight-multi" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "uninstall_postflight stanza checks" do | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:message) { "only a single uninstall_postflight stanza is allowed" } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has no uninstall_postflight stanza" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-zap-rmdir" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has only one uninstall_postflight stanza" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-uninstall-postflight" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has multiple uninstall_postflight stanzas" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-uninstall-postflight-multi" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "zap stanza checks" do | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:message) { "only a single zap stanza is allowed" } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has no zap stanza" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-uninstall-rmdir" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has only one zap stanza" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-zap-rmdir" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 08:41:32 +10:00
										 |  |  |       context "when the Cask has multiple zap stanzas" do | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |         let(:cask_token) { "with-zap-multi" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2017-10-30 20:47:40 -03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     describe "version checks" do | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:message) { "you should use version :latest instead of version 'latest'" } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       context "when version is 'latest'" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |         let(:only) { ["no_string_version_latest"] } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         let(:cask_token) { "version-latest-string" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when version is :latest" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |         let(:only) { ["sha256_no_check_if_latest"] } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         let(:cask_token) { "version-latest-with-checksum" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when version contains a colon" do | 
					
						
							|  |  |  |         let(:only) { ["version_special_characters"] } | 
					
						
							|  |  |  |         let(:cask_token) { "version-colon" } | 
					
						
							|  |  |  |         let(:message) { "version should not contain colons or slashes" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "sha256 checks" do | 
					
						
							|  |  |  |       context "when version is :latest and sha256 is not :no_check" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |         let(:only) { ["sha256_no_check_if_latest"] } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         let(:cask_token) { "version-latest-with-checksum" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_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 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |         let(:only) { ["sha256_actually_256"] } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         let(:cask_token) { "invalid-sha256" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_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 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |         let(:only) { ["sha256_invalid"] } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |         let(:cask_token) { "sha256-for-empty-string" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(/cannot use the sha256 for an empty string/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 00:53:47 +02:00
										 |  |  |     describe "hosting with livecheck checks" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["hosting_with_livecheck"] } | 
					
						
							| 
									
										
										
										
											2021-04-01 00:53:47 +02:00
										 |  |  |       let(:message) { /please add a livecheck/ } | 
					
						
							| 
									
										
										
										
											2018-03-26 21:25:00 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 00:53:47 +02:00
										 |  |  |       context "when the download does not use hosting with a livecheck" do | 
					
						
							| 
									
										
										
										
											2018-03-26 21:25:00 +10:00
										 |  |  |         let(:cask_token) { "basic-cask" } | 
					
						
							| 
									
										
										
										
											2018-03-28 22:05:56 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-03-26 21:25:00 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 00:53:47 +02:00
										 |  |  |       context "when the download is hosted on SourceForge and has a livecheck" do | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |         let(:cask_token) { "sourceforge-with-livecheck" } | 
					
						
							| 
									
										
										
										
											2018-06-05 16:42:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-06-15 17:01:27 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 00:53:47 +02:00
										 |  |  |       context "when the download is hosted on SourceForge and does not have a livecheck" do | 
					
						
							| 
									
										
										
										
											2018-06-15 17:01:27 +10:00
										 |  |  |         let(:cask_token) { "sourceforge-correct-url-format" } | 
					
						
							| 
									
										
										
										
											2021-04-07 02:19:16 +02:00
										 |  |  |         let(:online) { true } | 
					
						
							| 
									
										
										
										
											2018-06-15 17:01:27 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-06-15 17:01:27 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 00:53:47 +02:00
										 |  |  |       context "when the download is hosted on DevMate and has a livecheck" do | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |         let(:cask_token) { "devmate-with-livecheck" } | 
					
						
							| 
									
										
										
										
											2018-06-05 16:42:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-06-05 16:42:15 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 00:53:47 +02:00
										 |  |  |       context "when the download is hosted on DevMate and does not have a livecheck" do | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |         let(:cask_token) { "devmate-without-livecheck" } | 
					
						
							| 
									
										
										
										
											2018-06-15 17:01:27 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-06-15 17:01:27 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 00:53:47 +02:00
										 |  |  |       context "when the download is hosted on HockeyApp and has a livecheck" do | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |         let(:cask_token) { "hockeyapp-with-livecheck" } | 
					
						
							| 
									
										
										
										
											2018-06-05 16:42:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-06-05 16:42:15 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 00:53:47 +02:00
										 |  |  |       context "when the download is hosted on HockeyApp and does not have a livecheck" do | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |         let(:cask_token) { "hockeyapp-without-livecheck" } | 
					
						
							| 
									
										
										
										
											2018-06-05 16:42:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-06-05 16:42:15 +10:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |     describe "latest with livecheck checks" do | 
					
						
							|  |  |  |       let(:only) { ["latest_with_livecheck"] } | 
					
						
							|  |  |  |       let(:message) { "Casks with a `livecheck` should not use `version :latest`." } | 
					
						
							| 
									
										
										
										
											2018-03-27 20:56:01 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |       context "when the Cask is :latest and does not have a livecheck" do | 
					
						
							| 
									
										
										
										
											2018-03-27 20:56:01 +10:00
										 |  |  |         let(:cask_token) { "version-latest" } | 
					
						
							| 
									
										
										
										
											2018-03-28 22:05:56 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-03-27 20:56:01 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |       context "when the Cask is versioned and has a livecheck with skip information" do | 
					
						
							|  |  |  |         let(:cask_token) { "latest-with-livecheck-skip" } | 
					
						
							| 
									
										
										
										
											2018-03-28 22:05:56 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |         it { is_expected.to pass } | 
					
						
							| 
									
										
										
										
											2018-03-27 20:56:01 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-29 20:49:29 +02:00
										 |  |  |       context "when the Cask is versioned and has a livecheck" do | 
					
						
							|  |  |  |         let(:cask_token) { "latest-with-livecheck" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-03-27 20:56:01 +10:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-06 21:10:16 +01:00
										 |  |  |     describe "denylist checks" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["denylist"] } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       context "when the Cask is not on the denylist" do | 
					
						
							| 
									
										
										
										
											2019-09-08 09:09:37 -04:00
										 |  |  |         let(:cask_token) { "adobe-air" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it { is_expected.to pass } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |       context "when the Cask is on the denylist and" do | 
					
						
							|  |  |  |         context "when it's in the official Homebrew tap" do | 
					
						
							| 
									
										
										
										
											2019-09-08 09:09:37 -04:00
										 |  |  |           let(:cask_token) { "adobe-illustrator" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |           it { is_expected.to error_with(/#{cask_token} is not allowed: \w+/) } | 
					
						
							| 
									
										
										
										
											2019-09-08 09:09:37 -04:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |         context "when it isn't in the official Homebrew tap" do | 
					
						
							| 
									
										
										
										
											2019-09-08 09:09:37 -04:00
										 |  |  |           let(:cask_token) { "pharo" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           it { is_expected.to pass } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-12 16:13:46 +10:00
										 |  |  |     describe "latest with auto_updates checks" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["latest_with_auto_updates"] } | 
					
						
							| 
									
										
										
										
											2021-01-08 03:48:53 +01:00
										 |  |  |       let(:message) { "Casks with `version :latest` should not use `auto_updates`." } | 
					
						
							| 
									
										
										
										
											2018-07-12 16:13:46 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |       context "when the Cask is :latest and does not have auto_updates" do | 
					
						
							|  |  |  |         let(:cask_token) { "version-latest" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it { is_expected.to pass } | 
					
						
							| 
									
										
										
										
											2018-07-12 16:13:46 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when the Cask is versioned and does not have auto_updates" do | 
					
						
							|  |  |  |         let(:cask_token) { "basic-cask" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it { is_expected.to pass } | 
					
						
							| 
									
										
										
										
											2018-07-12 16:13:46 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when the Cask is versioned and has auto_updates" do | 
					
						
							|  |  |  |         let(:cask_token) { "auto-updates" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it { is_expected.to pass } | 
					
						
							| 
									
										
										
										
											2018-07-12 16:13:46 +10:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when the Cask is :latest and has auto_updates" do | 
					
						
							|  |  |  |         let(:cask_token) { "latest-with-auto-updates" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2018-07-12 16:13:46 +10:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |     describe "preferred download URL formats" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["download_url_format"] } | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:message) { /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" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with correct SourceForge URL format" do | 
					
						
							|  |  |  |         let(:cask_token) { "sourceforge-correct-url-format" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with correct SourceForge URL format for version :latest" do | 
					
						
							|  |  |  |         let(:cask_token) { "sourceforge-version-latest-correct-url-format" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2024-05-27 00:34:08 +08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-27 00:34:08 +08:00
										 |  |  |     describe "disable OSDN download url" do | 
					
						
							|  |  |  |       let(:only) { ["download_url_is_osdn"] } | 
					
						
							|  |  |  |       let(:message) { /OSDN download urls are disabled./ } | 
					
						
							|  |  |  |       let(:cask_token) { "osdn-urls" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-27 00:34:08 +08:00
										 |  |  |       context "when --strict is not passed" do | 
					
						
							|  |  |  |         it { is_expected.not_to error_with(message) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-27 00:34:08 +08:00
										 |  |  |       context "when --strict is passed" do | 
					
						
							|  |  |  |         let(:strict) { true } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-26 16:03:03 -07:00
										 |  |  |         it { is_expected.to error_with(message) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "generic artifact checks" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["generic_artifacts"] } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       context "with relative target" do | 
					
						
							|  |  |  |         let(:cask_token) { "generic-artifact-relative-target" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(/target must be.*absolute/) } | 
					
						
							| 
									
										
										
										
											2020-12-13 03:12:30 +01:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with user-relative target" do | 
					
						
							|  |  |  |         let(:cask_token) { "generic-artifact-user-relative-target" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(/target must be.*absolute/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with absolute target" do | 
					
						
							|  |  |  |         let(:cask_token) { "generic-artifact-absolute-target" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.not_to error_with(/target must be.*absolute/) } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "token conflicts" do | 
					
						
							|  |  |  |       let(:cask_token) { "with-binary" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when cask token conflicts with a core formula" do | 
					
						
							|  |  |  |         let(:formula_names) { %w[with-binary other-formula] } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-23 16:08:13 +01:00
										 |  |  |         it "warns about conflicts" do | 
					
						
							|  |  |  |           expect(audit).to receive(:core_formula_names).and_return(formula_names) | 
					
						
							|  |  |  |           expect(run).to error_with(/cask token conflicts/) | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe "audit of downloads" do | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       let(:only) { ["download"] } | 
					
						
							| 
									
										
										
										
											2022-08-01 14:30:04 +02:00
										 |  |  |       let(:cask_token) { "basic-cask" } | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       let(:cask) { Cask::CaskLoader.load(cask_token) } | 
					
						
							| 
									
										
										
										
											2020-07-21 19:05:55 +02:00
										 |  |  |       let(:download_double) { instance_double(Cask::Download) } | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       let(:message) { "Download Failed" } | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-21 19:05:55 +02:00
										 |  |  |       before do | 
					
						
							|  |  |  |         allow(audit).to receive(:download).and_return(download_double) | 
					
						
							| 
									
										
										
										
											2022-08-01 14:30:04 +02:00
										 |  |  |         allow(UnpackStrategy).to receive(:detect).and_return(nil) | 
					
						
							| 
									
										
										
										
											2020-07-21 19:05:55 +02:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-28 19:16:56 +00:00
										 |  |  |       it "when download and verification succeed it does not fail" do | 
					
						
							| 
									
										
										
										
											2022-08-01 14:30:04 +02:00
										 |  |  |         expect(download_double).to receive(:fetch).and_return(Pathname.new("/tmp/test.zip")) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         expect(run).to pass | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       it "when download fails it fails" do | 
					
						
							| 
									
										
										
										
											2020-11-19 18:12:16 +01:00
										 |  |  |         expect(download_double).to receive(:fetch).and_raise(StandardError.new(message)) | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         expect(run).to error_with(/#{message}/) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when an exception is raised" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       let(:cask) { instance_double(Cask::Cask) } | 
					
						
							| 
									
										
										
										
											2023-02-05 15:22:06 +01:00
										 |  |  |       let(:only) { ["description"] } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-08 09:09:37 -04:00
										 |  |  |       it "fails the audit" do | 
					
						
							|  |  |  |         expect(cask).to receive(:tap).and_raise(StandardError.new) | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         expect(run).to error_with(/exception while auditing/) | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-10 19:34:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |     describe "checking description" do | 
					
						
							| 
									
										
										
										
											2023-02-05 15:22:06 +01:00
										 |  |  |       let(:only) { ["description"] } | 
					
						
							| 
									
										
										
										
											2020-08-10 19:34:38 +02:00
										 |  |  |       let(:cask_token) { "without-description" } | 
					
						
							|  |  |  |       let(:cask) do | 
					
						
							|  |  |  |         tmp_cask cask_token.to_s, <<~RUBY | 
					
						
							|  |  |  |           cask '#{cask_token}' do | 
					
						
							|  |  |  |             version '1.0' | 
					
						
							|  |  |  |             sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a' | 
					
						
							|  |  |  |             url "https://brew.sh/" | 
					
						
							|  |  |  |             name 'Audit' | 
					
						
							|  |  |  |             homepage 'https://brew.sh/' | 
					
						
							|  |  |  |             app 'Audit.app' | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         RUBY | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when `new_cask` is true" do | 
					
						
							|  |  |  |         let(:new_cask) { true } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |         it "fails" do | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |           expect(run).to error_with(/should have a description/) | 
					
						
							| 
									
										
										
										
											2020-08-10 19:34:38 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 04:17:50 +02:00
										 |  |  |       context "when `new_cask` is false" do | 
					
						
							| 
									
										
										
										
											2020-08-10 19:34:38 +02:00
										 |  |  |         let(:new_cask) { false } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 23:52:24 +01:00
										 |  |  |         it "does not warn" do | 
					
						
							| 
									
										
										
										
											2023-03-31 01:25:36 +01:00
										 |  |  |           expect(run).not_to error_with(/should have a description/) | 
					
						
							| 
									
										
										
										
											2020-08-10 19:34:38 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       context "with description" do | 
					
						
							|  |  |  |         let(:cask_token) { "with-description" } | 
					
						
							|  |  |  |         let(:cask) do | 
					
						
							|  |  |  |           tmp_cask cask_token.to_s, <<~RUBY | 
					
						
							|  |  |  |             cask "#{cask_token}" do | 
					
						
							|  |  |  |               version "1.0" | 
					
						
							|  |  |  |               sha256 "8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a" | 
					
						
							|  |  |  |               url "https://brew.sh/\#{version}.zip" | 
					
						
							|  |  |  |               name "Audit" | 
					
						
							|  |  |  |               desc "Cask Auditor" | 
					
						
							|  |  |  |               homepage "https://brew.sh/" | 
					
						
							|  |  |  |               app "Audit.app" | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           RUBY | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-08-10 19:34:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |         it "passes" do | 
					
						
							|  |  |  |           expect(run).to pass | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-08-10 19:34:38 +02:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-09-08 22:12:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |     describe "checking verified" do | 
					
						
							|  |  |  |       let(:only) { %w[unnecessary_verified missing_verified no_match required_stanzas] } | 
					
						
							| 
									
										
										
										
											2020-09-08 22:12:26 +08:00
										 |  |  |       let(:cask_token) { "foo" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       context "when the url matches the homepage" do | 
					
						
							|  |  |  |         let(:cask) do | 
					
						
							|  |  |  |           tmp_cask cask_token.to_s, <<~RUBY | 
					
						
							|  |  |  |             cask '#{cask_token}' do | 
					
						
							|  |  |  |               version '1.0' | 
					
						
							|  |  |  |               sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a' | 
					
						
							|  |  |  |               url 'https://foo.brew.sh/foo.zip' | 
					
						
							|  |  |  |               name 'Audit' | 
					
						
							|  |  |  |               desc 'Audit Description' | 
					
						
							|  |  |  |               homepage 'https://foo.brew.sh' | 
					
						
							|  |  |  |               app 'Audit.app' | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           RUBY | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-09-08 22:12:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |         it { is_expected.to pass } | 
					
						
							| 
									
										
										
										
											2020-09-08 22:12:26 +08:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       context "when the url does not match the homepage" do | 
					
						
							|  |  |  |         let(:cask) do | 
					
						
							|  |  |  |           tmp_cask cask_token.to_s, <<~RUBY | 
					
						
							|  |  |  |             cask '#{cask_token}' do | 
					
						
							|  |  |  |               version "1.8.0_72,8.13.0.5" | 
					
						
							|  |  |  |               sha256 "8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a" | 
					
						
							|  |  |  |               url "https://brew.sh/foo-\#{version.after_comma}.zip" | 
					
						
							|  |  |  |               name "Audit" | 
					
						
							|  |  |  |               desc "Audit Description" | 
					
						
							|  |  |  |               homepage "https://foo.example.org" | 
					
						
							|  |  |  |               app "Audit.app" | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           RUBY | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-09-08 22:12:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(/a 'verified' parameter has to be added/) } | 
					
						
							| 
									
										
										
										
											2020-09-08 22:12:26 +08:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       context "when the url does not match the homepage with verified" do | 
					
						
							|  |  |  |         let(:cask) do | 
					
						
							|  |  |  |           tmp_cask cask_token.to_s, <<~RUBY | 
					
						
							|  |  |  |             cask "#{cask_token}" do | 
					
						
							|  |  |  |               version "1.8.0_72,8.13.0.5" | 
					
						
							|  |  |  |               sha256 "8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a" | 
					
						
							|  |  |  |               url "https://brew.sh/foo-\#{version.after_comma}.zip", verified: "brew.sh" | 
					
						
							|  |  |  |               name "Audit" | 
					
						
							|  |  |  |               desc "Audit Description" | 
					
						
							|  |  |  |               homepage "https://foo.example.org" | 
					
						
							|  |  |  |               app "Audit.app" | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           RUBY | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2022-08-23 15:52:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |         it { is_expected.to pass } | 
					
						
							| 
									
										
										
										
											2021-03-12 10:26:59 -07:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |       context "when there is no homepage" do | 
					
						
							|  |  |  |         let(:cask) do | 
					
						
							|  |  |  |           tmp_cask cask_token.to_s, <<~RUBY | 
					
						
							|  |  |  |             cask '#{cask_token}' do | 
					
						
							|  |  |  |               version '1.8.0_72,8.13.0.5' | 
					
						
							|  |  |  |               sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a' | 
					
						
							|  |  |  |               url 'https://brew.sh/foo.zip' | 
					
						
							|  |  |  |               name 'Audit' | 
					
						
							|  |  |  |               desc 'Audit Description' | 
					
						
							|  |  |  |               app 'Audit.app' | 
					
						
							| 
									
										
										
										
											2022-08-23 15:52:10 +02:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2022-09-13 10:54:05 +02:00
										 |  |  |           RUBY | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-13 21:15:59 +01:00
										 |  |  |         it { is_expected.to error_with(/a homepage stanza is required/) } | 
					
						
							| 
									
										
										
										
											2022-09-06 11:46:40 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2021-03-12 10:26:59 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2024-09-30 22:22:41 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe "checking deprecate/disable" do | 
					
						
							|  |  |  |       let(:only) { ["deprecate_disable"] } | 
					
						
							|  |  |  |       let(:cask_token) { "deprecated-cask" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when deprecate/disable is used with a valid reason" do | 
					
						
							|  |  |  |         let(:cask) do | 
					
						
							|  |  |  |           tmp_cask cask_token.to_s, <<~RUBY | 
					
						
							|  |  |  |             cask '#{cask_token}' do | 
					
						
							|  |  |  |               version "1.0" | 
					
						
							|  |  |  |                 sha256 "8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a" | 
					
						
							|  |  |  |                 url "https://brew.sh/foo.zip" | 
					
						
							|  |  |  |                 name "Audit" | 
					
						
							|  |  |  |                 desc "Cask Auditor" | 
					
						
							|  |  |  |                 homepage "https://brew.sh/" | 
					
						
							|  |  |  |                 app "Audit.app" | 
					
						
							|  |  |  |                 deprecate! date: "2021-01-01", because: :foobar | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           RUBY | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "fails" do | 
					
						
							|  |  |  |           expect(run).to error_with(/foobar is not a valid deprecate! or disable! reason/) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "when deprecate/disable is used with an invalid reason" do | 
					
						
							|  |  |  |         let(:cask) do | 
					
						
							|  |  |  |           tmp_cask cask_token.to_s, <<~RUBY | 
					
						
							|  |  |  |             cask '#{cask_token}' do | 
					
						
							|  |  |  |               version "1.0" | 
					
						
							|  |  |  |                 sha256 "8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a" | 
					
						
							|  |  |  |                 url "https://brew.sh/foo.zip" | 
					
						
							|  |  |  |                 name "Audit" | 
					
						
							|  |  |  |                 desc "Cask Auditor" | 
					
						
							|  |  |  |                 homepage "https://brew.sh/" | 
					
						
							|  |  |  |                 app "Audit.app" | 
					
						
							|  |  |  |                 disable! date: "2021-01-01", because: :discontinued | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           RUBY | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it "passes" do | 
					
						
							|  |  |  |           expect(run).to pass | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |