Merge pull request #16903 from apainintheneck/prevent-unexpected-network-calls-in-tests
Prevent unexpected network calls in tests
This commit is contained in:
commit
7b2bfee363
@ -256,11 +256,15 @@ module Homebrew
|
|||||||
paths = []
|
paths = []
|
||||||
|
|
||||||
if formula_path.exist? ||
|
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
|
paths << formula_path
|
||||||
end
|
end
|
||||||
if cask_path.exist? ||
|
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
|
paths << cask_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -22,11 +22,7 @@ RSpec.describe Cask::CaskLoader::FromAPILoader, :cask do
|
|||||||
describe ".can_load?" do
|
describe ".can_load?" do
|
||||||
include_context "with API setup", "test-opera"
|
include_context "with API setup", "test-opera"
|
||||||
|
|
||||||
context "when not using the API" do
|
context "when not using the API", :no_api do
|
||||||
before do
|
|
||||||
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns false" do
|
it "returns false" do
|
||||||
expect(described_class.try_new(token)).to be_nil
|
expect(described_class.try_new(token)).to be_nil
|
||||||
end
|
end
|
||||||
|
|||||||
@ -30,11 +30,7 @@ RSpec.describe Cask::CaskLoader, :cask do
|
|||||||
.and_return(cask_renames)
|
.and_return(cask_renames)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when not using the API" do
|
context "when not using the API", :no_api do
|
||||||
before do
|
|
||||||
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "warns when using the short token" do
|
it "warns when using the short token" do
|
||||||
expect do
|
expect do
|
||||||
expect(described_class.for("version-newest")).to be_a Cask::CaskLoader::FromPathLoader
|
expect(described_class.for("version-newest")).to be_a Cask::CaskLoader::FromPathLoader
|
||||||
@ -67,11 +63,7 @@ RSpec.describe Cask::CaskLoader, :cask do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when not using the API" do
|
context "when not using the API", :no_api do
|
||||||
before do
|
|
||||||
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when a cask is migrated" do
|
context "when a cask is migrated" do
|
||||||
let(:token) { "local-caffeine" }
|
let(:token) { "local-caffeine" }
|
||||||
|
|
||||||
|
|||||||
@ -46,13 +46,13 @@ RSpec.describe Cask::Cask, :cask do
|
|||||||
expect(c.token).to eq("caffeine")
|
expect(c.token).to eq("caffeine")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an instance of the Cask from a URL" do
|
it "returns an instance of the Cask from a URL", :needs_utils_curl, :no_api do
|
||||||
c = Cask::CaskLoader.load("file://#{tap_path}/Casks/local-caffeine.rb")
|
c = Cask::CaskLoader.load("file://#{tap_path}/Casks/local-caffeine.rb")
|
||||||
expect(c).to be_a(described_class)
|
expect(c).to be_a(described_class)
|
||||||
expect(c.token).to eq("local-caffeine")
|
expect(c.token).to eq("local-caffeine")
|
||||||
end
|
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", :needs_utils_curl, :no_api do
|
||||||
expect do
|
expect do
|
||||||
Cask::CaskLoader.load("file://#{tap_path}/Casks/notacask.rb")
|
Cask::CaskLoader.load("file://#{tap_path}/Casks/notacask.rb")
|
||||||
end.to raise_error(Cask::CaskUnavailableError)
|
end.to raise_error(Cask::CaskUnavailableError)
|
||||||
|
|||||||
@ -3,6 +3,11 @@
|
|||||||
require "utils"
|
require "utils"
|
||||||
|
|
||||||
RSpec.describe Cask::Info, :cask do
|
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
|
it "displays some nice info about the specified Cask" do
|
||||||
expect do
|
expect do
|
||||||
described_class.info(Cask::CaskLoader.load("local-transmission"))
|
described_class.info(Cask::CaskLoader.load("local-transmission"))
|
||||||
|
|||||||
@ -119,7 +119,7 @@ RSpec.describe Formulary do
|
|||||||
expect(described_class.factory(formula_path)).to be_a(Formula)
|
expect(described_class.factory(formula_path)).to be_a(Formula)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a Formula when given a URL" do
|
it "returns a Formula when given a URL", :needs_utils_curl, :no_api do
|
||||||
formula = described_class.factory("file://#{formula_path}")
|
formula = described_class.factory("file://#{formula_path}")
|
||||||
expect(formula).to be_a(Formula)
|
expect(formula).to be_a(Formula)
|
||||||
end
|
end
|
||||||
@ -383,6 +383,10 @@ RSpec.describe Formulary do
|
|||||||
before do
|
before do
|
||||||
ENV.delete("HOMEBREW_NO_INSTALL_FROM_API")
|
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
|
# don't try to load/fetch gcc/glibc
|
||||||
allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false)
|
allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -165,6 +165,19 @@ RSpec.configure do |config|
|
|||||||
skip "Requires network connection." unless ENV["HOMEBREW_TEST_ONLINE"]
|
skip "Requires network connection." unless ENV["HOMEBREW_TEST_ONLINE"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.before do |example|
|
||||||
|
next if example.metadata.key?(:needs_network)
|
||||||
|
next if example.metadata.key?(:needs_utils_curl)
|
||||||
|
|
||||||
|
allow(Utils::Curl).to receive(:curl_executable).and_raise(<<~ERROR)
|
||||||
|
Unexpected call to Utils::Curl.curl_executable without setting :needs_network or :needs_utils_curl.
|
||||||
|
ERROR
|
||||||
|
end
|
||||||
|
|
||||||
|
config.before(:each, :no_api) do
|
||||||
|
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
|
||||||
|
end
|
||||||
|
|
||||||
config.before(:each, :needs_svn) do
|
config.before(:each, :needs_svn) do
|
||||||
svn_shim = HOMEBREW_SHIMS_PATH/"shared/svn"
|
svn_shim = HOMEBREW_SHIMS_PATH/"shared/svn"
|
||||||
skip "Subversion is not installed." unless quiet_system svn_shim, "--version"
|
skip "Subversion is not installed." unless quiet_system svn_shim, "--version"
|
||||||
|
|||||||
@ -192,7 +192,7 @@ RSpec.describe Tap do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#remote" do
|
describe "#remote" do
|
||||||
it "returns the remote URL" do
|
it "returns the remote URL", :needs_network do
|
||||||
setup_git_repo
|
setup_git_repo
|
||||||
|
|
||||||
expect(homebrew_foo_tap.remote).to eq("https://github.com/Homebrew/homebrew-foo")
|
expect(homebrew_foo_tap.remote).to eq("https://github.com/Homebrew/homebrew-foo")
|
||||||
@ -488,8 +488,7 @@ RSpec.describe Tap do
|
|||||||
expect(described_class.to_a).to include(CoreTap.instance)
|
expect(described_class.to_a).to include(CoreTap.instance)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "omits the core tap without the api" do
|
it "omits the core tap without the api", :no_api do
|
||||||
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
|
|
||||||
expect(described_class.to_a).not_to include(CoreTap.instance)
|
expect(described_class.to_a).not_to include(CoreTap.instance)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user