| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-18 17:02:08 +02:00
										 |  |  | require "missing_formula" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe Homebrew::MissingFormula do | 
					
						
							| 
									
										
										
										
											2018-04-14 01:39:00 +02:00
										 |  |  |   describe "::reason" do | 
					
						
							| 
									
										
										
										
											2017-03-18 17:02:08 +02:00
										 |  |  |     subject { described_class.reason("gem") } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |     it { is_expected.not_to be_nil } | 
					
						
							| 
									
										
										
										
											2017-03-18 17:02:08 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-06 21:10:16 +01:00
										 |  |  |   describe "::disallowed_reason" do | 
					
						
							|  |  |  |     matcher :disallow do |name| | 
					
						
							| 
									
										
										
										
											2018-03-27 10:58:25 +02:00
										 |  |  |       match do |expected| | 
					
						
							| 
									
										
										
										
											2020-06-06 21:10:16 +01:00
										 |  |  |         expected.disallowed_reason(name) | 
					
						
							| 
									
										
										
										
											2018-03-27 10:58:25 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-03-18 17:02:08 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-06 21:10:16 +01:00
										 |  |  |     it { is_expected.to disallow("gem") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("pip") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("pil") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("macruby") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("lzma") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("sshpass") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("gsutil") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("gfortran") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("play") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("haskell-platform") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("mysqldump-secure") } | 
					
						
							|  |  |  |     it { is_expected.to disallow("ngrok") } | 
					
						
							|  |  |  |     it("disallows Xcode", :needs_macos) { is_expected.to disallow("xcode") } | 
					
						
							| 
									
										
										
										
											2017-03-18 17:02:08 +02:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-14 01:39:00 +02:00
										 |  |  |   describe "::tap_migration_reason" do | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  |     subject { described_class.tap_migration_reason(formula) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     before do | 
					
						
							|  |  |  |       tap_path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" | 
					
						
							|  |  |  |       tap_path.mkpath | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |       (tap_path/"tap_migrations.json").write <<~JSON | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  |         { "migrated-formula": "homebrew/bar" } | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |       JSON | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "with a migrated formula" do | 
					
						
							|  |  |  |       let(:formula) { "migrated-formula" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.not_to be_nil } | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "with a missing formula" do | 
					
						
							|  |  |  |       let(:formula) { "missing-formula" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  |       it { is_expected.to be_nil } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-14 01:39:00 +02:00
										 |  |  |   describe "::deleted_reason" do | 
					
						
							| 
									
										
										
										
											2017-04-22 12:26:18 +01:00
										 |  |  |     subject { described_class.deleted_reason(formula, silent: true) } | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     before do | 
					
						
							|  |  |  |       tap_path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" | 
					
						
							|  |  |  |       tap_path.mkpath | 
					
						
							|  |  |  |       (tap_path/"deleted-formula.rb").write "placeholder" | 
					
						
							| 
									
										
										
										
											2017-12-30 21:18:02 +00:00
										 |  |  |       ENV.delete "GIT_AUTHOR_DATE" | 
					
						
							|  |  |  |       ENV.delete "GIT_COMMITTER_DATE" | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       tap_path.cd do | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |         system "git", "init" | 
					
						
							|  |  |  |         system "git", "add", "--all" | 
					
						
							|  |  |  |         system "git", "commit", "-m", "initial state" | 
					
						
							|  |  |  |         system "git", "rm", "deleted-formula.rb" | 
					
						
							|  |  |  |         system "git", "commit", "-m", "delete formula 'deleted-formula'" | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "with a deleted formula" do | 
					
						
							|  |  |  |       let(:formula) { "homebrew/foo/deleted-formula" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.not_to be_nil } | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "with a formula that never existed" do | 
					
						
							|  |  |  |       let(:formula) { "homebrew/foo/missing-formula" } | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  |       it { is_expected.to be_nil } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2019-03-21 17:18:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "::cask_reason", :cask do | 
					
						
							| 
									
										
										
										
											2019-03-24 15:28:34 -04:00
										 |  |  |     subject { described_class.cask_reason(formula, show_info: show_info) } | 
					
						
							| 
									
										
										
										
											2019-03-21 17:18:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-24 15:28:34 -04:00
										 |  |  |     context "with a formula name that is a cask and show_info: false" do | 
					
						
							| 
									
										
										
										
											2019-03-21 17:18:21 -04:00
										 |  |  |       let(:formula) { "local-caffeine" } | 
					
						
							| 
									
										
										
										
											2019-03-24 15:28:34 -04:00
										 |  |  |       let(:show_info) { false } | 
					
						
							| 
									
										
										
										
											2019-03-21 17:18:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-24 15:28:34 -04:00
										 |  |  |       it { is_expected.to match(/Found a cask named "local-caffeine" instead./) } | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |       it { is_expected.to match(/Try\n  brew install --cask local-caffeine/) } | 
					
						
							| 
									
										
										
										
											2019-03-21 17:18:21 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-24 15:28:34 -04:00
										 |  |  |     context "with a formula name that is a cask and show_info: true" do | 
					
						
							|  |  |  |       let(:formula) { "local-caffeine" } | 
					
						
							|  |  |  |       let(:show_info) { true } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-15 07:52:32 -07:00
										 |  |  |       it { is_expected.to match(/Found a cask named "local-caffeine" instead.\n\n==> local-caffeine: 1.2.3\n/) } | 
					
						
							| 
									
										
										
										
											2019-03-24 15:28:34 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "with a formula name that is not a cask" do | 
					
						
							| 
									
										
										
										
											2019-03-21 17:18:21 -04:00
										 |  |  |       let(:formula) { "missing-formula" } | 
					
						
							| 
									
										
										
										
											2019-03-24 15:28:34 -04:00
										 |  |  |       let(:show_info) { false } | 
					
						
							| 
									
										
										
										
											2019-03-21 17:18:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.to be_nil } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2019-07-20 14:09:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "::suggest_command", :cask do | 
					
						
							|  |  |  |     subject { described_class.suggest_command(name, command) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when installing" do | 
					
						
							| 
									
										
										
										
											2019-07-20 14:09:13 -04:00
										 |  |  |       let(:name) { "local-caffeine" } | 
					
						
							|  |  |  |       let(:command) { "install" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.to match(/Found a cask named "local-caffeine" instead./) } | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |       it { is_expected.to match(/Try\n  brew install --cask local-caffeine/) } | 
					
						
							| 
									
										
										
										
											2019-07-20 14:09:13 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when uninstalling" do | 
					
						
							| 
									
										
										
										
											2019-07-20 14:09:13 -04:00
										 |  |  |       let(:name) { "local-caffeine" } | 
					
						
							|  |  |  |       let(:command) { "uninstall" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.to be_nil } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       context "with described cask installed" do | 
					
						
							|  |  |  |         before do | 
					
						
							|  |  |  |           allow(Cask::Caskroom).to receive(:casks).and_return(["local-caffeine"]) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it { is_expected.to match(/Found a cask named "local-caffeine" instead./) } | 
					
						
							| 
									
										
										
										
											2020-11-18 08:10:21 +01:00
										 |  |  |         it { is_expected.to match(/Try\n  brew uninstall --cask local-caffeine/) } | 
					
						
							| 
									
										
										
										
											2019-07-20 14:09:13 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when getting info" do | 
					
						
							| 
									
										
										
										
											2019-07-20 14:09:13 -04:00
										 |  |  |       let(:name) { "local-caffeine" } | 
					
						
							|  |  |  |       let(:command) { "info" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.to match(/Found a cask named "local-caffeine" instead./) } | 
					
						
							|  |  |  |       it { is_expected.to match(/local-caffeine: 1.2.3/) } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-03-18 17:02:08 +02:00
										 |  |  | end |