Skip to content

Commit

Permalink
spec_helper: add :no_api test scope
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apainintheneck committed Mar 20, 2024
1 parent ad35db4 commit 74aea8e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 23 deletions.
Expand Up @@ -22,11 +22,7 @@
describe ".can_load?" do
include_context "with API setup", "test-opera"

context "when not using the API" do
before do
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
end

context "when not using the API", :no_api do
it "returns false" do
expect(described_class.try_new(token)).to be_nil
end
Expand Down
12 changes: 2 additions & 10 deletions Library/Homebrew/test/cask/cask_loader_spec.rb
Expand Up @@ -30,11 +30,7 @@
.and_return(cask_renames)
end

context "when not using the API" do
before do
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
end

context "when not using the API", :no_api do
it "warns when using the short token" do
expect do
expect(described_class.for("version-newest")).to be_a Cask::CaskLoader::FromPathLoader
Expand Down Expand Up @@ -67,11 +63,7 @@
end
end

context "when not using the API" do
before do
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
end

context "when not using the API", :no_api do
context "when a cask is migrated" do
let(:token) { "local-caffeine" }

Expand Down
6 changes: 2 additions & 4 deletions Library/Homebrew/test/cask/cask_spec.rb
Expand Up @@ -46,15 +46,13 @@
expect(c.token).to eq("caffeine")
end

it "returns an instance of the Cask from a URL", :needs_utils_curl do
expect(Homebrew::API).not_to receive(:fetch_json_api_file)
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")
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", :needs_utils_curl do
expect(Homebrew::API).not_to receive(:fetch_json_api_file)
it "raises an error when failing to download a Cask from a URL", :needs_utils_curl, :no_api do
expect do
Cask::CaskLoader.load("file://#{tap_path}/Casks/notacask.rb")
end.to raise_error(Cask::CaskUnavailableError)
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/test/formulary_spec.rb
Expand Up @@ -119,8 +119,7 @@ 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", :needs_utils_curl do
expect(Homebrew::API).not_to receive(:fetch_json_api_file)
it "returns a Formula when given a URL", :needs_utils_curl, :no_api do
formula = described_class.factory("file://#{formula_path}")
expect(formula).to be_a(Formula)
end
Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/test/spec_helper.rb
Expand Up @@ -174,6 +174,10 @@
ERROR
end

config.before(:each, :no_api) do
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
end

config.before(:each, :needs_svn) do
svn_shim = HOMEBREW_SHIMS_PATH/"shared/svn"
skip "Subversion is not installed." unless quiet_system svn_shim, "--version"
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/test/tap_spec.rb
Expand Up @@ -488,8 +488,7 @@ def setup_completion(link:)
expect(described_class.to_a).to include(CoreTap.instance)
end

it "omits the core tap without the api" do
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1"
it "omits the core tap without the api", :no_api do
expect(described_class.to_a).not_to include(CoreTap.instance)
end
end
Expand Down

0 comments on commit 74aea8e

Please sign in to comment.