From 9e65b61913a9031dfb630fbfa65ed4b1641f86a5 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/dev-cmd/cat_spec.rb | 2 +- Library/Homebrew/test/dev-cmd/edit_spec.rb | 2 +- Library/Homebrew/test/formulary_spec.rb | 4 ++++ Library/Homebrew/test/tap_spec.rb | 2 +- 6 files changed, 18 insertions(+), 5 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/dev-cmd/cat_spec.rb b/Library/Homebrew/test/dev-cmd/cat_spec.rb index 162e3d4f3d35c9..e7b63a6d5fb282 100644 --- a/Library/Homebrew/test/dev-cmd/cat_spec.rb +++ b/Library/Homebrew/test/dev-cmd/cat_spec.rb @@ -5,7 +5,7 @@ RSpec.describe "brew cat" do it_behaves_like "parseable arguments" - it "prints the content of a given Formula", :integration_test do + it "prints the content of a given Formula", :integration_test, :needs_network do formula_file = setup_test_formula "testball" content = formula_file.read diff --git a/Library/Homebrew/test/dev-cmd/edit_spec.rb b/Library/Homebrew/test/dev-cmd/edit_spec.rb index 09ccfbdc24ccfb..e3af2b4852b661 100644 --- a/Library/Homebrew/test/dev-cmd/edit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/edit_spec.rb @@ -5,7 +5,7 @@ RSpec.describe "brew edit" do it_behaves_like "parseable arguments" - it "opens a given Formula in an editor", :integration_test do + it "opens a given Formula in an editor", :integration_test, :needs_network do HOMEBREW_REPOSITORY.cd do system "git", "init" end diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 86631a3a667ddb..fa4d31b1ab959d 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -383,6 +383,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")