diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 8cd0e292bd..fbc361dd0e 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -129,7 +129,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin 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 when /^testball/ tarball = if OS.linux? @@ -174,14 +174,14 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin RUBY 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 class #{Formulary.class_s(name)} < Formula #{content.gsub(/^(?!$)/, " ")} end RUBY - CoreTap.instance.clear_cache + tap.clear_cache end end diff --git a/Library/Homebrew/test/untap_spec.rb b/Library/Homebrew/test/untap_spec.rb index eac2c0cb28..e88f3d27f6 100644 --- a/Library/Homebrew/test/untap_spec.rb +++ b/Library/Homebrew/test/untap_spec.rb @@ -3,21 +3,16 @@ require "untap" 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 def load_formula(name:, with_formula_file: false, mock_install: false) - formula = formula(name, tap:) do - url "https://brew.sh/foo-1.0.tgz" - 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 + formula = if with_formula_file + 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 mock_install @@ -66,11 +61,15 @@ RSpec.describe Homebrew::Untap do context "with non-core tap" do let(:tap) { Tap.fetch("homebrew", "foo") } + before do + tap.formula_dir.mkpath + end + include_examples "finds installed formulae in tap" end end - describe ".installed_casks_for" do + describe ".installed_casks_for", :cask do shared_examples "finds installed casks in tap" do def load_cask(token:, with_cask_file: false, mock_install: false) cask_loader = Cask::CaskLoader::FromContentLoader.new(<<~RUBY, tap:) @@ -90,10 +89,7 @@ RSpec.describe Homebrew::Untap do cask_path.write cask.source end - if mock_install - metadata_subdirectory = cask.metadata_subdir("Casks", timestamp: :now, create: true) - (metadata_subdirectory/"#{token}.rb").write cask.source - end + InstallHelper.install_with_caskfile(cask) if mock_install cask end