From 86dfebb1745a0bb5a20802a2b792834d554de4ea Mon Sep 17 00:00:00 2001 From: Patrick Linnane Date: Wed, 14 Oct 2026 20:50:52 -0700 Subject: [PATCH] Stop bundle specs leaking Tap and Cask doubles - `Homebrew::Bundle::Tap.taps` and `Homebrew::Bundle::Cask.casks` memoise whatever `Tap.select` and `Cask::Caskroom.casks` return, so the `instance_double`s stubbed in `tap_spec` and `dumper_spec` survived into later examples. - `npm_spec`'s `Installer.install!` example then hit rspec-mocks' "leaked into another example" error whenever a dumper example ran first in the same process, failing random test orders. Signed-off-by: Patrick Linnane --- Library/Homebrew/test/bundle/dumper_spec.rb | 6 ++++++ Library/Homebrew/test/bundle/tap_spec.rb | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/Library/Homebrew/test/bundle/dumper_spec.rb b/Library/Homebrew/test/bundle/dumper_spec.rb index 76214fb539431..8ee194523b55a 100644 --- a/Library/Homebrew/test/bundle/dumper_spec.rb +++ b/Library/Homebrew/test/bundle/dumper_spec.rb @@ -47,6 +47,12 @@ allow(Tap).to receive(:select).and_return([]) end + # `Tap.taps` and `Cask.casks` memoise the stubbed doubles, which must not outlive the example. + after do + Homebrew::Bundle::Tap.reset! + Homebrew::Bundle::Cask.reset! + end + it "generates output" do expect(dumper.build_brewfile( describe: false, no_restart: false, formulae: true, taps: true, casks: true, diff --git a/Library/Homebrew/test/bundle/tap_spec.rb b/Library/Homebrew/test/bundle/tap_spec.rb index 4b3c9fc3a008f..8408328cbed3c 100644 --- a/Library/Homebrew/test/bundle/tap_spec.rb +++ b/Library/Homebrew/test/bundle/tap_spec.rb @@ -6,6 +6,11 @@ require "bundle/tap" RSpec.describe Homebrew::Bundle::Tap do + # `taps` memoises the stubbed `Tap` doubles, which must not outlive the example. + after do + described_class.reset! + end + describe "dumping" do subject(:dumper) { described_class }