spec_helper: add :no_api test scope

This sets the HOMEBREW_NO_INSTALL_FROM_API environment variable
to prevent the selected tests from using the API. We will need
this as we transition to having the API be enabled by default
when running the tests but it's also nice as a sanity check
with the :needs_utils_curl scope in a few places.
This commit is contained in:
apainintheneck 2024-03-19 22:18:02 -07:00
parent ad35db4b24
commit 74aea8e92d
6 changed files with 11 additions and 23 deletions

View File

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

View File

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

View File

@ -46,15 +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", :needs_utils_curl do it "returns an instance of the Cask from a URL", :needs_utils_curl, :no_api do
expect(Homebrew::API).not_to receive(:fetch_json_api_file)
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", :needs_utils_curl do it "raises an error when failing to download a Cask from a URL", :needs_utils_curl, :no_api do
expect(Homebrew::API).not_to receive(:fetch_json_api_file)
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)

View File

@ -119,8 +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", :needs_utils_curl do it "returns a Formula when given a URL", :needs_utils_curl, :no_api do
expect(Homebrew::API).not_to receive(:fetch_json_api_file)
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

View File

@ -174,6 +174,10 @@ RSpec.configure do |config|
ERROR ERROR
end 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"

View File

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