untap_spec: use builtin spec helpers to simplify tests

This commit is contained in:
apainintheneck 2024-03-12 22:07:14 -07:00
parent 9daeaf6087
commit 9ff0f85335
2 changed files with 17 additions and 21 deletions

View File

@ -129,7 +129,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
end end
end end
def setup_test_formula(name, content = nil, bottle_block: nil) def setup_test_formula(name, content = nil, tap: CoreTap.instance, bottle_block: nil)
case name case name
when /^testball/ when /^testball/
tarball = if OS.linux? tarball = if OS.linux?
@ -174,14 +174,14 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
RUBY RUBY
end end
Formulary.core_path(name).tap do |formula_path| Formulary.find_formula_in_tap(name.downcase, tap).tap do |formula_path|
formula_path.write <<~RUBY formula_path.write <<~RUBY
class #{Formulary.class_s(name)} < Formula class #{Formulary.class_s(name)} < Formula
#{content.gsub(/^(?!$)/, " ")} #{content.gsub(/^(?!$)/, " ")}
end end
RUBY RUBY
CoreTap.instance.clear_cache tap.clear_cache
end end
end end

View File

@ -3,21 +3,16 @@
require "untap" require "untap"
RSpec.describe Homebrew::Untap do RSpec.describe Homebrew::Untap do
describe ".installed_formulae_for" do describe ".installed_formulae_for", :integration_test do
shared_examples "finds installed formulae in tap" do shared_examples "finds installed formulae in tap" do
def load_formula(name:, with_formula_file: false, mock_install: false) def load_formula(name:, with_formula_file: false, mock_install: false)
formula = formula(name, tap:) do formula = if with_formula_file
url "https://brew.sh/foo-1.0.tgz" path = setup_test_formula(name, tap:)
Formulary.factory(path)
else
formula(name, tap:) do
url "https://brew.sh/#{name}-1.0.tgz"
end end
if with_formula_file
class_name = name.split("_").map(&:capitalize).join
tap.formula_dir.mkpath
(tap.formula_dir/"#{name}.rb").write <<~RUBY
class #{class_name} < Formula
url "https://brew.sh/foo-1.0.tgz"
end
RUBY
end end
if mock_install if mock_install
@ -66,11 +61,15 @@ RSpec.describe Homebrew::Untap do
context "with non-core tap" do context "with non-core tap" do
let(:tap) { Tap.fetch("homebrew", "foo") } let(:tap) { Tap.fetch("homebrew", "foo") }
before do
tap.formula_dir.mkpath
end
include_examples "finds installed formulae in tap" include_examples "finds installed formulae in tap"
end end
end end
describe ".installed_casks_for" do describe ".installed_casks_for", :cask do
shared_examples "finds installed casks in tap" do shared_examples "finds installed casks in tap" do
def load_cask(token:, with_cask_file: false, mock_install: false) def load_cask(token:, with_cask_file: false, mock_install: false)
cask_loader = Cask::CaskLoader::FromContentLoader.new(<<~RUBY, tap:) cask_loader = Cask::CaskLoader::FromContentLoader.new(<<~RUBY, tap:)
@ -90,10 +89,7 @@ RSpec.describe Homebrew::Untap do
cask_path.write cask.source cask_path.write cask.source
end end
if mock_install InstallHelper.install_with_caskfile(cask) if mock_install
metadata_subdirectory = cask.metadata_subdir("Casks", timestamp: :now, create: true)
(metadata_subdirectory/"#{token}.rb").write cask.source
end
cask cask
end end