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.
This commit is contained in:
apainintheneck 2024-03-16 13:17:54 -07:00
parent b66097fa3d
commit ad35db4b24
4 changed files with 16 additions and 3 deletions

View File

@ -256,11 +256,15 @@ module Homebrew
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

View File

@ -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"))

View File

@ -384,6 +384,10 @@ RSpec.describe Formulary do
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

View File

@ -192,7 +192,7 @@ RSpec.describe Tap do
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")