Skip to content

Commit

Permalink
tests: fix tests that make unexpected network calls
Browse files Browse the repository at this point in the history
These were found with the Utils::Curl check and just turning
off the network on my computer and running the entire test suite.
  • Loading branch information
apainintheneck committed Mar 16, 2024
1 parent 1ca9755 commit 9e65b61
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
8 changes: 6 additions & 2 deletions Library/Homebrew/cli/named_args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/test/cask/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/dev-cmd/cat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/dev-cmd/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/test/formulary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/tap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9e65b61

Please sign in to comment.