| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "cli/named_args" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe Homebrew::CLI::NamedArgs do | 
					
						
							| 
									
										
										
										
											2024-01-26 11:36:08 -08:00
										 |  |  |   def setup_unredable_formula(name) | 
					
						
							|  |  |  |     error = FormulaUnreadableError.new(name, RuntimeError.new("testing")) | 
					
						
							|  |  |  |     allow(Formulary).to receive(:factory).with(name, any_args).and_raise(error) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-26 11:36:08 -08:00
										 |  |  |   def setup_unredable_cask(name) | 
					
						
							|  |  |  |     error = Cask::CaskUnreadableError.new(name, "testing") | 
					
						
							|  |  |  |     allow(Cask::CaskLoader).to receive(:load).with(name, any_args).and_raise(error) | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-26 11:36:08 -08:00
										 |  |  |     config = instance_double(Cask::Config) | 
					
						
							|  |  |  |     allow(Cask::Config).to receive(:from_args).and_return(config) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  |   let(:foo) do | 
					
						
							|  |  |  |     formula "foo" do | 
					
						
							|  |  |  |       url "https://brew.sh" | 
					
						
							|  |  |  |       version "1.0" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let(:bar) do | 
					
						
							|  |  |  |     formula "bar" do | 
					
						
							|  |  |  |       url "https://brew.sh" | 
					
						
							|  |  |  |       version "1.0" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let(:baz) do | 
					
						
							| 
									
										
										
										
											2024-07-12 04:20:54 +01:00
										 |  |  |     Cask::CaskLoader::FromContentLoader.new(+<<~RUBY, tap: CoreCaskTap.instance).load(config: nil) | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  |       cask "baz" do | 
					
						
							|  |  |  |         version "1.0" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  |   let(:foo_cask) do | 
					
						
							| 
									
										
										
										
											2024-07-12 04:20:54 +01:00
										 |  |  |     Cask::CaskLoader::FromContentLoader.new(+<<~RUBY, tap: CoreCaskTap.instance).load(config: nil) | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  |       cask "foo" do | 
					
						
							|  |  |  |         version "1.0" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  |   describe "#to_formulae" do | 
					
						
							|  |  |  |     it "returns formulae" do | 
					
						
							| 
									
										
										
										
											2020-08-17 12:40:23 -04:00
										 |  |  |       stub_formula_loader foo, call_original: true | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  |       stub_formula_loader bar | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(described_class.new("foo", "bar").to_formulae).to eq [foo, bar] | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when a Formula is unavailable" do | 
					
						
							|  |  |  |       expect { described_class.new("mxcl").to_formulae }.to raise_error FormulaUnavailableError | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns an empty array when there are no Formulae" do | 
					
						
							|  |  |  |       expect(described_class.new.to_formulae).to be_empty | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#to_formulae_and_casks" do | 
					
						
							| 
									
										
										
										
											2022-12-03 22:08:01 -08:00
										 |  |  |     it "returns formulae and casks", :needs_macos do | 
					
						
							| 
									
										
										
										
											2020-08-17 12:40:23 -04:00
										 |  |  |       stub_formula_loader foo, call_original: true | 
					
						
							|  |  |  |       stub_cask_loader baz, call_original: true | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(described_class.new("foo", "baz").to_formulae_and_casks).to eq [foo, baz] | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     context "when both formula and cask are present" do | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         stub_formula_loader foo | 
					
						
							|  |  |  |         stub_cask_loader foo_cask | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns formula by default" do | 
					
						
							|  |  |  |         expect(described_class.new("foo").to_formulae_and_casks).to eq [foo] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns formula if loading formula only" do | 
					
						
							|  |  |  |         expect(described_class.new("foo").to_formulae_and_casks(only: :formula)).to eq [foo] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns cask if loading cask only" do | 
					
						
							|  |  |  |         expect(described_class.new("foo").to_formulae_and_casks(only: :cask)).to eq [foo_cask] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-12 04:20:54 +01:00
										 |  |  |     context "when a non-core formula and a core cask are present" do | 
					
						
							|  |  |  |       let(:non_core_formula) do | 
					
						
							|  |  |  |         formula "foo", tap: Tap.fetch("some/tap") do | 
					
						
							|  |  |  |           url "https://brew.sh" | 
					
						
							|  |  |  |           version "1.0" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         stub_formula_loader non_core_formula, "foo" | 
					
						
							|  |  |  |         stub_cask_loader foo_cask | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns the cask by default" do | 
					
						
							|  |  |  |         expect(described_class.new("foo").to_formulae_and_casks).to eq [foo_cask] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns formula if loading formula only" do | 
					
						
							|  |  |  |         expect(described_class.new("foo").to_formulae_and_casks(only: :formula)).to eq [non_core_formula] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns cask if loading cask only" do | 
					
						
							|  |  |  |         expect(described_class.new("foo").to_formulae_and_casks(only: :cask)).to eq [foo_cask] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  |     context "when both formula and cask are unreadable" do | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         setup_unredable_formula "foo" | 
					
						
							|  |  |  |         setup_unredable_cask "foo" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "raises an error" do | 
					
						
							| 
									
										
										
										
											2021-01-27 10:02:07 -08:00
										 |  |  |         expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaUnreadableError) | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "raises an error if loading formula only" do | 
					
						
							|  |  |  |         expect { described_class.new("foo").to_formulae_and_casks(only: :formula) } | 
					
						
							|  |  |  |           .to raise_error(FormulaUnreadableError) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "raises an error if loading cask only" do | 
					
						
							|  |  |  |         expect { described_class.new("foo").to_formulae_and_casks(only: :cask) } | 
					
						
							|  |  |  |           .to raise_error(Cask::CaskUnreadableError) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when neither formula nor cask is present" do | 
					
						
							|  |  |  |       expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaOrCaskUnavailableError) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-03 22:08:01 -08:00
										 |  |  |     it "returns formula when formula is present and cask is unreadable", :needs_macos do | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  |       stub_formula_loader foo | 
					
						
							|  |  |  |       setup_unredable_cask "foo" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(described_class.new("foo").to_formulae_and_casks).to eq [foo] | 
					
						
							| 
									
										
										
										
											2021-01-27 10:03:44 -08:00
										 |  |  |       expect { described_class.new("foo").to_formulae_and_casks }.to output(/Failed to load cask: foo/).to_stderr | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-03 22:08:01 -08:00
										 |  |  |     it "returns cask when formula is unreadable and cask is present", :needs_macos do | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  |       setup_unredable_formula "foo" | 
					
						
							|  |  |  |       stub_cask_loader foo_cask | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(described_class.new("foo").to_formulae_and_casks).to eq [foo_cask] | 
					
						
							| 
									
										
										
										
											2021-01-27 10:03:44 -08:00
										 |  |  |       expect { described_class.new("foo").to_formulae_and_casks }.to output(/Failed to load formula: foo/).to_stderr | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-03 22:08:01 -08:00
										 |  |  |     it "raises an error when formula is absent and cask is unreadable", :needs_macos do | 
					
						
							| 
									
										
										
										
											2021-01-25 18:41:25 -08:00
										 |  |  |       setup_unredable_cask "foo" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(Cask::CaskUnreadableError) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when formula is unreadable and cask is absent" do | 
					
						
							|  |  |  |       setup_unredable_formula "foo" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaUnreadableError) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#to_resolved_formulae" do | 
					
						
							|  |  |  |     it "returns resolved formulae" do | 
					
						
							|  |  |  |       allow(Formulary).to receive(:resolve).and_return(foo, bar) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(described_class.new("foo", "bar").to_resolved_formulae).to eq [foo, bar] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#to_resolved_formulae_to_casks" do | 
					
						
							| 
									
										
										
										
											2022-12-03 22:08:01 -08:00
										 |  |  |     it "returns resolved formulae, as well as casks", :needs_macos do | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  |       allow(Formulary).to receive(:resolve).and_call_original | 
					
						
							|  |  |  |       allow(Formulary).to receive(:resolve).with("foo", any_args).and_return foo | 
					
						
							| 
									
										
										
										
											2020-08-17 12:40:23 -04:00
										 |  |  |       stub_cask_loader baz, call_original: true | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       resolved_formulae, casks = described_class.new("foo", "baz").to_resolved_formulae_to_casks | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(resolved_formulae).to eq [foo] | 
					
						
							|  |  |  |       expect(casks).to eq [baz] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#to_casks" do | 
					
						
							|  |  |  |     it "returns casks" do | 
					
						
							|  |  |  |       stub_cask_loader baz | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(described_class.new("baz").to_casks).to eq [baz] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-19 13:58:55 -04:00
										 |  |  |   describe "#to_kegs" do | 
					
						
							|  |  |  |     before do | 
					
						
							|  |  |  |       (HOMEBREW_CELLAR/"foo/1.0").mkpath | 
					
						
							|  |  |  |       (HOMEBREW_CELLAR/"foo/2.0").mkpath | 
					
						
							|  |  |  |       (HOMEBREW_CELLAR/"bar/1.0").mkpath | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "resolves kegs with #resolve_kegs" do | 
					
						
							|  |  |  |       expect(described_class.new("foo", "bar").to_kegs.map(&:name)).to eq ["foo", "foo", "bar"] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "resolves kegs with multiple versions with #resolve_keg" do | 
					
						
							| 
									
										
										
										
											2021-05-24 09:17:52 -04:00
										 |  |  |       expect(described_class.new("foo").to_kegs.map { |k| k.version.version.to_s }.sort).to eq ["1.0", "2.0"] | 
					
						
							| 
									
										
										
										
											2021-05-19 13:58:55 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-20 12:08:10 -04:00
										 |  |  |     it "when there are no matching kegs returns an empty array" do | 
					
						
							| 
									
										
										
										
											2021-05-19 13:58:55 -04:00
										 |  |  |       expect(described_class.new.to_kegs).to be_empty | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2024-07-20 21:41:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when a Keg is unavailable" do | 
					
						
							|  |  |  |       expect { described_class.new("baz").to_kegs }.to raise_error NoSuchKegError | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when a keg specifies a tap" do | 
					
						
							|  |  |  |       let(:tab) { instance_double(Tab, tap: Tap.fetch("user", "repo")) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       before do | 
					
						
							|  |  |  |         allow_any_instance_of(Keg).to receive(:tab).and_return(tab) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns kegs if no tap is specified" do | 
					
						
							|  |  |  |         stub_formula_loader bar, "user/repo/bar" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(described_class.new("bar").to_kegs.map(&:name)).to eq ["bar"] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "returns kegs if the tap is specified" do | 
					
						
							|  |  |  |         stub_formula_loader bar, "user/repo/bar" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(described_class.new("user/repo/bar").to_kegs.map(&:name)).to eq ["bar"] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "raises an error if there is no tap match" do | 
					
						
							|  |  |  |         stub_formula_loader bar, "other/tap/bar" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-16 05:46:14 +01:00
										 |  |  |         expect { described_class.new("other/tap/bar").to_kegs }.to raise_error(NoSuchKegError, %r{from tap other/tap}) | 
					
						
							| 
									
										
										
										
											2024-07-20 21:41:34 -04:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-05-19 13:58:55 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-19 09:34:18 -04:00
										 |  |  |   describe "#to_default_kegs" do | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  |     before do | 
					
						
							|  |  |  |       (HOMEBREW_CELLAR/"foo/1.0").mkpath | 
					
						
							|  |  |  |       (HOMEBREW_CELLAR/"bar/1.0").mkpath | 
					
						
							| 
									
										
										
										
											2021-05-20 12:06:23 -04:00
										 |  |  |       linked_path = (HOMEBREW_CELLAR/"foo/2.0") | 
					
						
							|  |  |  |       linked_path.mkpath | 
					
						
							|  |  |  |       Keg.new(linked_path).link | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-19 10:29:40 -04:00
										 |  |  |     it "resolves kegs with #resolve_default_keg" do | 
					
						
							| 
									
										
										
										
											2021-05-19 09:34:18 -04:00
										 |  |  |       expect(described_class.new("foo", "bar").to_default_kegs.map(&:name)).to eq ["foo", "bar"] | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-21 11:52:17 -04:00
										 |  |  |     it "resolves the default keg" do | 
					
						
							|  |  |  |       expect(described_class.new("foo").to_default_kegs.map { |k| k.version.version.to_s }).to eq ["2.0"] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-20 12:06:23 -04:00
										 |  |  |     it "when there are no matching kegs returns an empty array" do | 
					
						
							| 
									
										
										
										
											2021-05-19 09:34:18 -04:00
										 |  |  |       expect(described_class.new.to_default_kegs).to be_empty | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-23 16:09:35 -04:00
										 |  |  |   describe "#to_latest_kegs" do | 
					
						
							|  |  |  |     before do | 
					
						
							|  |  |  |       (HOMEBREW_CELLAR/"foo/1.0").mkpath | 
					
						
							|  |  |  |       (HOMEBREW_CELLAR/"foo/2.0").mkpath | 
					
						
							|  |  |  |       (HOMEBREW_CELLAR/"bar/1.0").mkpath | 
					
						
							| 
									
										
										
										
											2021-08-06 22:35:16 -04:00
										 |  |  |       (HOMEBREW_CELLAR/"baz/HEAD-1").mkpath | 
					
						
							| 
									
										
										
										
											2021-08-06 22:34:30 -04:00
										 |  |  |       head2 = HOMEBREW_CELLAR/"baz/HEAD-2" | 
					
						
							|  |  |  |       head2.mkpath | 
					
						
							|  |  |  |       (head2/"INSTALL_RECEIPT.json").write (TEST_FIXTURE_DIR/"receipt.json").read | 
					
						
							| 
									
										
										
										
											2021-05-23 16:09:35 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "resolves the latest kegs with #resolve_latest_keg" do | 
					
						
							| 
									
										
										
										
											2021-08-04 18:51:39 -04:00
										 |  |  |       latest_kegs = described_class.new("foo", "bar", "baz").to_latest_kegs | 
					
						
							|  |  |  |       expect(latest_kegs.map(&:name)).to eq ["foo", "bar", "baz"] | 
					
						
							| 
									
										
										
										
											2021-08-06 22:34:30 -04:00
										 |  |  |       expect(latest_kegs.map { |k| k.version.version.to_s }).to eq ["2.0", "1.0", "HEAD-2"] | 
					
						
							| 
									
										
										
										
											2021-05-23 16:09:35 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "when there are no matching kegs returns an empty array" do | 
					
						
							|  |  |  |       expect(described_class.new.to_latest_kegs).to be_empty | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  |   describe "#to_kegs_to_casks" do | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  |     before do | 
					
						
							|  |  |  |       (HOMEBREW_CELLAR/"foo/1.0").mkpath | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-03 22:08:01 -08:00
										 |  |  |     it "returns kegs, as well as casks", :needs_macos do | 
					
						
							| 
									
										
										
										
											2020-08-17 12:40:23 -04:00
										 |  |  |       stub_cask_loader baz, call_original: true | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  |       kegs, casks = described_class.new("foo", "baz").to_kegs_to_casks | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  |       expect(kegs.map(&:name)).to eq ["foo"] | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  |       expect(casks).to eq [baz] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "#homebrew_tap_cask_names" do | 
					
						
							|  |  |  |     it "returns an array of casks from homebrew-cask" do | 
					
						
							|  |  |  |       expect(described_class.new("foo", "homebrew/cask/local-caffeine").homebrew_tap_cask_names) | 
					
						
							|  |  |  |         .to eq ["homebrew/cask/local-caffeine"] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns an empty array when there are no matching casks" do | 
					
						
							|  |  |  |       expect(described_class.new("foo").homebrew_tap_cask_names).to be_empty | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-09-09 22:10:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "#to_paths" do | 
					
						
							|  |  |  |     let(:existing_path) { mktmpdir } | 
					
						
							|  |  |  |     let(:formula_path) { Pathname("/path/to/foo.rb") } | 
					
						
							|  |  |  |     let(:cask_path) { Pathname("/path/to/baz.rb") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     before do | 
					
						
							|  |  |  |       allow(formula_path).to receive(:exist?).and_return(true) | 
					
						
							|  |  |  |       allow(cask_path).to receive(:exist?).and_return(true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       allow(Formulary).to receive(:path).and_call_original | 
					
						
							|  |  |  |       allow(Cask::CaskLoader).to receive(:path).and_call_original | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-03 22:08:01 -08:00
										 |  |  |     it "returns taps, cask formula and existing paths", :needs_macos do | 
					
						
							| 
									
										
										
										
											2020-09-09 22:10:33 +02:00
										 |  |  |       expect(Formulary).to receive(:path).with("foo").and_return(formula_path) | 
					
						
							|  |  |  |       expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(described_class.new("homebrew/core", "foo", "baz", existing_path.to_s).to_paths) | 
					
						
							|  |  |  |         .to eq [Tap.fetch("homebrew/core").path, formula_path, cask_path, existing_path] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-03 22:08:01 -08:00
										 |  |  |     it "returns both cask and formula paths if they exist", :needs_macos do | 
					
						
							| 
									
										
										
										
											2020-09-09 22:10:33 +02:00
										 |  |  |       expect(Formulary).to receive(:path).with("foo").and_return(formula_path) | 
					
						
							|  |  |  |       expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(described_class.new("foo", "baz").to_paths).to eq [formula_path, cask_path] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 16:01:04 +01:00
										 |  |  |     it "returns only formulae when `only: :formula` is specified" do | 
					
						
							| 
									
										
										
										
											2020-09-09 22:10:33 +02:00
										 |  |  |       expect(Formulary).to receive(:path).with("foo").and_return(formula_path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 16:01:04 +01:00
										 |  |  |       expect(described_class.new("foo", "baz").to_paths(only: :formula)).to eq [formula_path, Formulary.path("baz")] | 
					
						
							| 
									
										
										
										
											2020-09-09 22:10:33 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 16:01:04 +01:00
										 |  |  |     it "returns only casks when `only: :cask` is specified" do | 
					
						
							| 
									
										
										
										
											2020-09-09 22:10:33 +02:00
										 |  |  |       expect(Cask::CaskLoader).to receive(:path).with("foo").and_return(cask_path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-19 16:01:04 +01:00
										 |  |  |       expect(described_class.new("foo", "baz").to_paths(only: :cask)).to eq [cask_path, Cask::CaskLoader.path("baz")] | 
					
						
							| 
									
										
										
										
											2020-09-09 22:10:33 +02:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "#to_taps" do | 
					
						
							|  |  |  |     it "returns taps" do | 
					
						
							|  |  |  |       taps = described_class.new("homebrew/foo", "bar/baz") | 
					
						
							|  |  |  |       expect(taps.to_taps.map(&:name)).to eq %w[homebrew/foo bar/baz] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error for invalid tap" do | 
					
						
							|  |  |  |       taps = described_class.new("homebrew/foo", "barbaz") | 
					
						
							| 
									
										
										
										
											2024-04-08 16:38:32 +01:00
										 |  |  |       expect { taps.to_taps }.to raise_error(Tap::InvalidNameError, /Invalid tap name/) | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "#to_installed_taps" do | 
					
						
							|  |  |  |     before do | 
					
						
							|  |  |  |       (HOMEBREW_REPOSITORY/"Library/Taps/homebrew/homebrew-foo").mkpath | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns installed taps" do | 
					
						
							|  |  |  |       taps = described_class.new("homebrew/foo") | 
					
						
							|  |  |  |       expect(taps.to_installed_taps.map(&:name)).to eq %w[homebrew/foo] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error for uninstalled tap" do | 
					
						
							|  |  |  |       taps = described_class.new("homebrew/foo", "bar/baz") | 
					
						
							|  |  |  |       expect { taps.to_installed_taps }.to raise_error(TapUnavailableError) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error for invalid tap" do | 
					
						
							|  |  |  |       taps = described_class.new("homebrew/foo", "barbaz") | 
					
						
							| 
									
										
										
										
											2024-04-08 16:38:32 +01:00
										 |  |  |       expect { taps.to_installed_taps }.to raise_error(Tap::InvalidNameError, /Invalid tap name/) | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-08-14 13:48:03 -04:00
										 |  |  | end |