From 0420c70cbf1d811be3fd7ebc2bbfc1e255224f49 Mon Sep 17 00:00:00 2001 From: Andrii Furmanets Date: Sun, 28 Dec 2025 11:57:47 +0200 Subject: [PATCH] Fix which command test isolation --- .../test_gem_commands_which_command.rb | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/rubygems/test_gem_commands_which_command.rb b/test/rubygems/test_gem_commands_which_command.rb index cbd5b5ef14ba..4aad6c85e965 100644 --- a/test/rubygems/test_gem_commands_which_command.rb +++ b/test/rubygems/test_gem_commands_which_command.rb @@ -38,7 +38,13 @@ def test_execute_directory end def test_execute_one_missing - # TODO: this test fails in isolation + original_gem_home = ENV["GEM_HOME"] + original_gem_path = ENV["GEM_PATH"] + + ENV["GEM_HOME"] = @gemhome + ENV["GEM_PATH"] = @gemhome + Gem.use_paths(@gemhome) + Gem::Specification.reset util_foo_bar @@ -53,6 +59,21 @@ def test_execute_one_missing assert_equal "#{@foo_bar.full_gem_path}/lib/foo_bar.rb\n", @ui.output assert_match(/Can.t find Ruby library file or shared library missinglib\n/, @ui.error) + ensure + if original_gem_home + ENV["GEM_HOME"] = original_gem_home + else + ENV.delete("GEM_HOME") + end + + if original_gem_path + ENV["GEM_PATH"] = original_gem_path + else + ENV.delete("GEM_PATH") + end + + Gem.use_paths(@gemhome) + Gem::Specification.reset end def test_execute_missing