| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  | require "exceptions" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe MultipleVersionsInstalledError do | 
					
						
							| 
									
										
										
										
											2020-09-09 11:02:43 -07:00
										 |  |  |   subject { | 
					
						
							|  |  |  |     described_class.new <<~EOS | 
					
						
							|  |  |  |       foo has multiple installed versions | 
					
						
							|  |  |  |       Run `brew uninstall --force foo` to remove all versions. | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-09 11:02:43 -07:00
										 |  |  |   its(:to_s) { | 
					
						
							|  |  |  |     is_expected.to eq <<~EOS | 
					
						
							|  |  |  |       foo has multiple installed versions | 
					
						
							|  |  |  |       Run `brew uninstall --force foo` to remove all versions. | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe NoSuchKegError do | 
					
						
							|  |  |  |   subject { described_class.new("foo") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to eq("No such keg: #{HOMEBREW_CELLAR}/foo") } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe FormulaValidationError do | 
					
						
							|  |  |  |   subject { described_class.new("foo", "sha257", "magic") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { | 
					
						
							| 
									
										
										
										
											2018-09-20 13:40:38 +01:00
										 |  |  |     expect(subject.to_s).to eq(%q(invalid attribute for formula 'foo': sha257 ("magic"))) | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe FormulaUnavailableError do | 
					
						
							|  |  |  |   subject { described_class.new("foo") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#dependent_s" do | 
					
						
							|  |  |  |     it "returns nil if there is no dependent" do | 
					
						
							|  |  |  |       expect(subject.dependent_s).to be nil | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns nil if it depended on by itself" do | 
					
						
							|  |  |  |       subject.dependent = "foo" | 
					
						
							|  |  |  |       expect(subject.dependent_s).to be nil | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns a string if there is a dependent" do | 
					
						
							|  |  |  |       subject.dependent = "foobar" | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       expect(subject.dependent_s).to eq(" (dependency of foobar)") | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   context "without a dependent" do | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |     its(:to_s) { is_expected.to eq('No available formula with the name "foo".') } | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   context "with a dependent" do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |     before do | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |       subject.dependent = "foobar" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     its(:to_s) { | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |       expect(subject.to_s).to eq('No available formula with the name "foo" (dependency of foobar).') | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe TapFormulaUnavailableError do | 
					
						
							|  |  |  |   subject { described_class.new(tap, "foo") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:tap) { double(Tap, user: "u", repo: "r", to_s: "u/r", installed?: false) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to match(%r{Please tap it and then try again: brew tap u/r}) } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe FormulaClassUnavailableError do | 
					
						
							|  |  |  |   subject { described_class.new("foo", "foo.rb", "Foo", list) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:mod) do | 
					
						
							|  |  |  |     Module.new do | 
					
						
							|  |  |  |       class Bar < Requirement; end | 
					
						
							| 
									
										
										
										
											2020-11-30 16:27:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |       class Baz < Formula; end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   context "no classes" do | 
					
						
							|  |  |  |     let(:list) { [] } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |     its(:to_s) { | 
					
						
							| 
									
										
										
										
											2018-09-20 13:40:38 +01:00
										 |  |  |       expect(subject.to_s).to match(/Expected to find class Foo, but found no classes\./) | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   context "class not derived from Formula" do | 
					
						
							|  |  |  |     let(:list) { [mod.const_get(:Bar)] } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |     its(:to_s) { | 
					
						
							| 
									
										
										
										
											2018-09-20 13:40:38 +01:00
										 |  |  |       expect(subject.to_s).to match(/Expected to find class Foo, but only found: Bar \(not derived from Formula!\)\./) | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   context "class derived from Formula" do | 
					
						
							|  |  |  |     let(:list) { [mod.const_get(:Baz)] } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |     its(:to_s) { is_expected.to match(/Expected to find class Foo, but only found: Baz\./) } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe FormulaUnreadableError do | 
					
						
							|  |  |  |   subject { described_class.new("foo", formula_error) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:formula_error) { LoadError.new("bar") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to eq("foo: bar") } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe TapUnavailableError do | 
					
						
							|  |  |  |   subject { described_class.new("foo") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to eq("No available tap foo.\n") } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe TapAlreadyTappedError do | 
					
						
							|  |  |  |   subject { described_class.new("foo") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to eq("Tap foo already tapped.\n") } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe BuildError do | 
					
						
							|  |  |  |   subject { described_class.new(formula, "badprg", %w[arg1 arg2], {}) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:formula) { double(Formula, name: "foo") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to eq("Failed executing: badprg arg1 arg2") } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe OperationInProgressError do | 
					
						
							|  |  |  |   subject { described_class.new("foo") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to match(/Operation already in progress for foo/) } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe FormulaInstallationAlreadyAttemptedError do | 
					
						
							|  |  |  |   subject { described_class.new(formula) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:formula) { double(Formula, full_name: "foo/bar") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to eq("Formula installation already attempted: foo/bar") } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe FormulaConflictError do | 
					
						
							|  |  |  |   subject { described_class.new(formula, [conflict]) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:formula) { double(Formula, full_name: "foo/qux") } | 
					
						
							|  |  |  |   let(:conflict) { double(name: "bar", reason: "I decided to") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to match(/Please `brew unlink bar` before continuing\./) } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe CompilerSelectionError do | 
					
						
							|  |  |  |   subject { described_class.new(formula) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:formula) { double(Formula, full_name: "foo") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to match(/foo cannot be built with any available compilers\./) } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe CurlDownloadStrategyError do | 
					
						
							|  |  |  |   context "file does not exist" do | 
					
						
							|  |  |  |     subject { described_class.new("file:///tmp/foo") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |     its(:to_s) { is_expected.to eq("File does not exist: /tmp/foo") } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   context "download failed" do | 
					
						
							| 
									
										
										
										
											2018-08-06 16:23:07 +02:00
										 |  |  |     subject { described_class.new("https://brew.sh") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-06 16:23:07 +02:00
										 |  |  |     its(:to_s) { is_expected.to eq("Download failed: https://brew.sh") } | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe ErrorDuringExecution do | 
					
						
							| 
									
										
										
										
											2018-07-16 23:17:16 +02:00
										 |  |  |   subject { described_class.new(["badprg", "arg1", "arg2"], status: status) } | 
					
						
							| 
									
										
										
										
											2018-09-20 09:07:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-16 23:17:16 +02:00
										 |  |  |   let(:status) { instance_double(Process::Status, exitstatus: 17) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-16 23:17:16 +02:00
										 |  |  |   its(:to_s) { is_expected.to eq("Failure while executing; `badprg arg1 arg2` exited with 17.") } | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe ChecksumMismatchError do | 
					
						
							|  |  |  |   subject { described_class.new("/file.tar.gz", hash1, hash2) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:hash1) { double(hash_type: "sha256", to_s: "deadbeef") } | 
					
						
							|  |  |  |   let(:hash2) { double(hash_type: "sha256", to_s: "deadcafe") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to match(/SHA256 mismatch/) } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe ResourceMissingError do | 
					
						
							|  |  |  |   subject { described_class.new(formula, resource) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:formula) { double(Formula, full_name: "bar") } | 
					
						
							|  |  |  |   let(:resource) { double(inspect: "<resource foo>") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to eq("bar does not define resource <resource foo>") } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe DuplicateResourceError do | 
					
						
							|  |  |  |   subject { described_class.new(resource) } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:resource) { double(inspect: "<resource foo>") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   its(:to_s) { is_expected.to eq("Resource <resource foo> is defined more than once") } | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-19 12:22:32 -07:00
										 |  |  | describe BottleFormulaUnavailableError do | 
					
						
							|  |  |  |   subject { described_class.new("/foo.bottle.tar.gz", "foo/1.0/.brew/foo.rb") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  |   let(:formula) { double(Formula, full_name: "foo") } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-19 12:22:32 -07:00
										 |  |  |   its(:to_s) { is_expected.to match(/This bottle does not contain the formula file/) } | 
					
						
							| 
									
										
										
										
											2017-02-14 17:45:20 +01:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2019-10-11 09:34:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe BuildFlagsError do | 
					
						
							|  |  |  |   subject { described_class.new(["-s"]) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   its(:to_s) { is_expected.to match(/flag:\s+-s\nrequires building tools/) } | 
					
						
							|  |  |  | end |