From e96313f6eddbd0d516f6fff79f7c717eed4db304 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 17 Feb 2024 13:00:50 -0800 Subject: [PATCH] formulary_spec: update API tests to avoid mocking Stop mocking the formulary loader method. We just need to set the environment variable so that it knows to load things from the API. Fix spec that doesn't work with the `CoreTap.formula_names`. That method assumes that we always have a valid `ruby_source_path` in the API JSON even though that was optional for a while after launching the API if my memory serves me. It's probably fine to assume this should always be set though and I changed it to use `Hash#fetch` to give use better error messages if something goes wrong in the future. Remove unused `allow(x).to receive(y).and_call_original` in tap spec. --- Library/Homebrew/tap.rb | 3 ++- Library/Homebrew/test/formulary_spec.rb | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 26ed2f11c5730..b55c274fffa11 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -1169,7 +1169,8 @@ def formula_files_by_name name, formula_hash = item # If there's more than one item with the same path: use the longer one to prioritise more specific results. existing_path = hash[name] - new_path = File.join(tap_path, formula_hash["ruby_source_path"]) # Pathname equivalent is slow in a tight loop + # Pathname equivalent is slow in a tight loop + new_path = File.join(tap_path, formula_hash.fetch("ruby_source_path")) hash[name] = Pathname(new_path) if existing_path.nil? || existing_path.to_s.length < new_path.length end end diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 33a0355729cb1..07903bbc4af59 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -158,8 +158,6 @@ class Wrong#{described_class.class_s(formula_name)} < Formula context "with installed Formula" do before do - allow(described_class).to receive(:loader_for).and_call_original - # don't try to load/fetch gcc/glibc allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false) end @@ -329,6 +327,7 @@ def formula_json_contents(extra_items = {}) "run_type" => "immediate", "working_dir" => "/$HOME", }, + "ruby_source_path" => "Formula/#{formula_name}.rb", }.merge(extra_items), } end @@ -378,7 +377,7 @@ def formula_json_contents(extra_items = {}) end before do - allow(described_class).to receive(:loader_for).and_return(described_class::FormulaAPILoader.new(formula_name)) + ENV.delete("HOMEBREW_NO_INSTALL_FROM_API") # don't try to load/fetch gcc/glibc allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false)