Skip to content

Fix gem which command test isolation#9222

Merged
hsbt merged 3 commits intoruby:masterfrom
afurm:fix-which-command-test-isolation
Mar 16, 2026
Merged

Fix gem which command test isolation#9222
hsbt merged 3 commits intoruby:masterfrom
afurm:fix-which-command-test-isolation

Conversation

@afurm
Copy link
Copy Markdown
Member

@afurm afurm commented Dec 28, 2025

Problem

The gem which command reports the filesystem path for a requireable file; test_execute_one_missing verifies it prints the found path and errors on a missing file. The test fails when run in isolation because it relies on gem path/spec state set by other tests.

Fix

Set GEM_HOME/GEM_PATH to @gemhome, call Gem.use_paths(@gemhome), and reset the spec cache before the test runs. Restore the env and gem paths in an ensure block and reset the spec cache afterward.

Testing

  • ruby -Ilib:test:bundler/lib test/rubygems/test_gem_commands_which_command.rb -n test_execute_one_missing

@afurm afurm force-pushed the fix-which-command-test-isolation branch from 55c51d4 to bf8c2a3 Compare December 28, 2025 10:13
@afurm afurm force-pushed the fix-which-command-test-isolation branch from bf8c2a3 to 0420c70 Compare December 28, 2025 10:13
@hsbt
Copy link
Copy Markdown
Member

hsbt commented Mar 11, 2026

@afurm Sorry my late response. The test currently passes in isolation on master without any changes:

$ ruby -Ilib:test:bundler/lib test/rubygems/test_gem_commands_which_command.rb -n test_execute_one_missing
1 tests, 5 assertions, 0 failures, 0 errors

The TODO comment is simply outdated. I think we just need to remove it rather than adding extra setup/teardown logic.

@afurm
Copy link
Copy Markdown
Member Author

afurm commented Mar 14, 2026

@afurm Sorry my late response. The test currently passes in isolation on master without any changes:

$ ruby -Ilib:test:bundler/lib test/rubygems/test_gem_commands_which_command.rb -n test_execute_one_missing
1 tests, 5 assertions, 0 failures, 0 errors

The TODO comment is simply outdated. I think we just need to remove it rather than adding extra setup/teardown logic.

Removed comment. Thank you

@hsbt hsbt merged commit 8b405fa into ruby:master Mar 16, 2026
106 of 108 checks passed
@afurm afurm deleted the fix-which-command-test-isolation branch March 16, 2026 04:48
hsbt added a commit that referenced this pull request Mar 25, 2026
Fix gem which command test isolation

(cherry picked from commit 8b405fa)
hsbt added a commit that referenced this pull request Mar 25, 2026
Fix gem which command test isolation

(cherry picked from commit 8b405fa)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants