Skip to content

Commit

Permalink
tests: add exceptions for tests that use curl to download local files
Browse files Browse the repository at this point in the history
These are acceptable ways to use curl in local, non-network tests.
  • Loading branch information
apainintheneck committed Mar 16, 2024
1 parent 9e65b61 commit 0ad15b6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Library/Homebrew/test/cask/cask_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/test/formulary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0ad15b6

Please sign in to comment.