Skip to content

Commit e301625

Browse files
committed
Fix bundler environment isolation in integration tests
Use Bundler.with_unbundled_env to wrap spec execution to prevent bundler state pollution between test runs. This fixes issues where non-Rails tests would fail after Rails integration tests because bundler was using cached configuration from the Rails test bundle. Also clear RUBYOPT in the env to prevent automatic bundler/setup loading from CI or previous tests.
1 parent ccdca7f commit e301625

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

bin/integrations

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# bin/integrations batch retry # Run tests matching 'batch' OR 'retry'
1111
# bin/integrations -v fifo # Run with verbose output
1212

13+
require 'bundler'
1314
require 'fileutils'
1415
require 'timeout'
1516

@@ -88,9 +89,11 @@ class IntegrationRunner
8889
end
8990

9091
def run_spec(spec)
92+
# Start with a clean bundler environment to prevent pollution between tests
9193
env = {
9294
'BUNDLE_GEMFILE' => spec[:gemfile],
93-
'RAILS_ENV' => 'test'
95+
'RAILS_ENV' => 'test',
96+
'RUBYOPT' => nil # Clear any -rbundler/setup from CI or previous tests
9497
}
9598

9699
# Install dependencies if using a local Gemfile
@@ -131,8 +134,13 @@ class IntegrationRunner
131134

132135
begin
133136
Timeout.timeout(TIMEOUT) do
134-
IO.popen(env, cmd, chdir: spec[:directory], err: [:child, :out]) do |io|
135-
io.each_line { |line| output << line }
137+
# Use unbundled env to prevent pollution from previous test runs
138+
# This is especially important after Rails integration tests that use
139+
# bundle install --standalone with different gem versions
140+
Bundler.with_unbundled_env do
141+
IO.popen(env, cmd, chdir: spec[:directory], err: [:child, :out]) do |io|
142+
io.each_line { |line| output << line }
143+
end
136144
end
137145
end
138146

0 commit comments

Comments
 (0)