From 1adddc5e9a195dac91da131594d8c0da4da1b28c Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 16 Mar 2024 13:17:54 -0700 Subject: [PATCH] tests: fix tests that make unexpected network calls These were found with the Utils::Curl check and just turning off the network on my computer and running the entire test suite. --- Library/Homebrew/cli/named_args.rb | 8 ++++++-- Library/Homebrew/test/cask/info_spec.rb | 5 +++++ Library/Homebrew/test/formulary_spec.rb | 4 ++++ Library/Homebrew/test/tap_spec.rb | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cli/named_args.rb b/Library/Homebrew/cli/named_args.rb index 1b30ef7d6b9f25..284c18aa9bbe4e 100644 --- a/Library/Homebrew/cli/named_args.rb +++ b/Library/Homebrew/cli/named_args.rb @@ -256,11 +256,15 @@ def to_paths(only: parent&.only_formula_or_cask, recurse_tap: false) paths = [] if formula_path.exist? || - (!CoreTap.instance.installed? && Homebrew::API::Formula.all_formulae.key?(path.basename.to_s)) + (!Homebrew::EnvConfig.no_install_from_api? && + !CoreTap.instance.installed? && + Homebrew::API::Formula.all_formulae.key?(path.basename.to_s)) paths << formula_path end if cask_path.exist? || - (!CoreCaskTap.instance.installed? && Homebrew::API::Cask.all_casks.key?(path.basename.to_s)) + (!Homebrew::EnvConfig.no_install_from_api? && + !CoreCaskTap.instance.installed? && + Homebrew::API::Cask.all_casks.key?(path.basename.to_s)) paths << cask_path end diff --git a/Library/Homebrew/test/cask/info_spec.rb b/Library/Homebrew/test/cask/info_spec.rb index 2c5a5aefc01953..8710a8ba70e216 100644 --- a/Library/Homebrew/test/cask/info_spec.rb +++ b/Library/Homebrew/test/cask/info_spec.rb @@ -3,6 +3,11 @@ require "utils" RSpec.describe Cask::Info, :cask do + before do + # Prevent unnecessary network requests in `Utils::Analytics.cask_output` + ENV["HOMEBREW_NO_ANALYTICS"] = "1" + end + it "displays some nice info about the specified Cask" do expect do described_class.info(Cask::CaskLoader.load("local-transmission")) diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 3bc5c5ee054278..8e34f0fb42179d 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -384,6 +384,10 @@ def formula_json_contents(extra_items = {}) before do ENV.delete("HOMEBREW_NO_INSTALL_FROM_API") + # avoid unnecessary network calls + allow(Homebrew::API::Formula).to receive_messages(all_aliases: {}, all_renames: {}) + allow(CoreTap.instance).to receive(:tap_migrations).and_return({}) + # don't try to load/fetch gcc/glibc allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false) end diff --git a/Library/Homebrew/test/tap_spec.rb b/Library/Homebrew/test/tap_spec.rb index 93e9317565c10c..1c0bec5ee378a9 100644 --- a/Library/Homebrew/test/tap_spec.rb +++ b/Library/Homebrew/test/tap_spec.rb @@ -192,7 +192,7 @@ def setup_completion(link:) end describe "#remote" do - it "returns the remote URL" do + it "returns the remote URL", :needs_network do setup_git_repo expect(homebrew_foo_tap.remote).to eq("https://github.com/Homebrew/homebrew-foo")