From de4bb5ac388703d916021439f9f420f87fb9e69c Mon Sep 17 00:00:00 2001 From: Edouard CHIN Date: Fri, 19 Dec 2025 01:42:42 +0100 Subject: [PATCH] Fix leaky tests: - While working on #9210, I found those leaky tests which break the test suite. They remove Bundler constants without setting them back. The reason it's not a problem on master is because there are no tests that install gems in the same process (all tests shell out to `bundle install`). --- bundler/spec/bundler/plugin/events_spec.rb | 12 +++++++++++- bundler/spec/bundler/plugin_spec.rb | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bundler/spec/bundler/plugin/events_spec.rb b/bundler/spec/bundler/plugin/events_spec.rb index 28d70c6fdddd..77e5fdb74cb5 100644 --- a/bundler/spec/bundler/plugin/events_spec.rb +++ b/bundler/spec/bundler/plugin/events_spec.rb @@ -2,7 +2,17 @@ RSpec.describe Bundler::Plugin::Events do context "plugin events" do - before { Bundler::Plugin::Events.send :reset } + before do + @old_constants = Bundler::Plugin::Events.constants.map {|name| [name, Bundler::Plugin::Events.const_get(name)] } + Bundler::Plugin::Events.send :reset + end + + after do + Bundler::Plugin::Events.send(:reset) + Hash[@old_constants].each do |name, value| + Bundler::Plugin::Events.send(:define, name, value) + end + end describe "#define" do it "raises when redefining a constant" do diff --git a/bundler/spec/bundler/plugin_spec.rb b/bundler/spec/bundler/plugin_spec.rb index fea392500067..e416772a3672 100644 --- a/bundler/spec/bundler/plugin_spec.rb +++ b/bundler/spec/bundler/plugin_spec.rb @@ -279,6 +279,7 @@ s.write "plugins.rb", code end + @old_constants = Bundler::Plugin::Events.constants.map {|name| [name, Bundler::Plugin::Events.const_get(name)] } Bundler::Plugin::Events.send(:reset) Bundler::Plugin::Events.send(:define, :EVENT1, "event-1") Bundler::Plugin::Events.send(:define, :EVENT2, "event-2") @@ -291,6 +292,13 @@ allow(index).to receive(:load_paths).with("foo-plugin").and_return([]) end + after do + Bundler::Plugin::Events.send(:reset) + Hash[@old_constants].each do |name, value| + Bundler::Plugin::Events.send(:define, name, value) + end + end + let(:code) { <<-RUBY } Bundler::Plugin::API.hook("event-1") { puts "hook for event 1" } RUBY