Skip to content

Fix generator tests - #1054

Merged
dpep merged 3 commits into
mainfrom
rails-main-generator-tests
Oct 3, 2026
Merged

dpep merged 3 commits into
mainfrom
rails-main-generator-tests

Conversation

@dpep

@dpep dpep commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the seed-dependent rails main canary failure in test_rails (example).

Rails main compares database configs by value (HashConfig#==), so establish_connection reuses the existing pool for the same :memory: config. UpdateGeneratorTest's teardown only checked the connection back in, so tables leaked between tests: table "flipper_features" already exists.

  • Teardown now calls ActiveRecord::Base.remove_connection, which drops the pool.
  • silence restores $stdout in an ensure. Without it, that one failure left $stdout as a StringIO, and 9 later tests failed in capture with can't convert Tempfile into StringIO.

dpep and others added 3 commits October 3, 2026 10:06
Rails main compares database configs by value, so establish_connection
with an identical :memory: config reuses the existing pool, and closing
the connection only checks it back in. Tables created by one test leaked
into the next ("table flipper_features already exists"). Remove the
connection in teardown so each test gets a fresh database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Otherwise $stdout stays a StringIO and every later generator test fails
with "can't convert Tempfile into StringIO", burying the real failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

teardown do
ActiveRecord::Base.connection.close
ActiveRecord::Base.remove_connection

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the pool, not just the connection: Rails reuses a pool for an identical config, which would keep this :memory: db alive across tests.

Comment thread test_rails/helper.rb
output.string
ensure
$stderr = original_stderr
$stdout = original_stdout

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore even on failure, or later tests inherit the StringIO

@dpep dpep changed the title Fix generator tests on rails main Fix generator tests Oct 3, 2026
@dpep
dpep marked this pull request as ready for review October 3, 2026 17:44
@dpep
dpep requested a review from bkeepers October 3, 2026 17:45
@dpep
dpep merged commit 6d6fbeb into main Oct 3, 2026
48 checks passed
@dpep
dpep deleted the rails-main-generator-tests branch October 3, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant