From 0ad15b62e016214b8edaf3f70f387168ccc940ba Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 16 Mar 2024 13:19:46 -0700 Subject: [PATCH] tests: add exceptions for tests that use curl to download local files These are acceptable ways to use curl in local, non-network tests. --- Library/Homebrew/test/cask/cask_spec.rb | 6 ++++-- Library/Homebrew/test/formulary_spec.rb | 3 ++- Library/Homebrew/test/spec_helper.rb | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index fea5589a37025c..68a881d2d89fb7 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -46,13 +46,15 @@ expect(c.token).to eq("caffeine") end - it "returns an instance of the Cask from a URL" do + it "returns an instance of the Cask from a URL", :allow_utils_curl do + expect(Homebrew::API).not_to receive(:fetch_json_api_file) c = Cask::CaskLoader.load("file://#{tap_path}/Casks/local-caffeine.rb") expect(c).to be_a(described_class) expect(c.token).to eq("local-caffeine") end - it "raises an error when failing to download a Cask from a URL" do + it "raises an error when failing to download a Cask from a URL", :allow_utils_curl do + expect(Homebrew::API).not_to receive(:fetch_json_api_file) expect do Cask::CaskLoader.load("file://#{tap_path}/Casks/notacask.rb") end.to raise_error(Cask::CaskUnavailableError) diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index fa4d31b1ab959d..7b31cc0e038d56 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -119,7 +119,8 @@ class Wrong#{described_class.class_s(formula_name)} < Formula expect(described_class.factory(formula_path)).to be_a(Formula) end - it "returns a Formula when given a URL" do + it "returns a Formula when given a URL", :allow_utils_curl do + expect(Homebrew::API).not_to receive(:fetch_json_api_file) formula = described_class.factory("file://#{formula_path}") expect(formula).to be_a(Formula) end diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 1b3292dc3d6f35..3b26f04a214c7d 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -173,6 +173,7 @@ config.before do |example| next if example.metadata.key?(:needs_network) + next if example.metadata.key?(:allow_utils_curl) DISALLOWED_UTILS_CURL_METHODS.each do |method| allow(Utils::Curl).to receive(method).and_raise(<<~ERROR)