Home / Companies / Mergify / Blog / Post Details
Content Deep Dive

RSpec system specs see an empty database. database_cleaner is why.

Blog post from Mergify

Post Details
Company
Date Published
Author
-
Word Count
1,098
Language
English
Hacker News Points
-
Summary

The blog post by Rémy Duthu discusses the challenges of using the database_cleaner gem in testing Rails applications, particularly when dealing with RSpec system specs and JavaScript-driven tests. It explains how Capybara's separate browser connection can cause transactional fixtures to fail, as the browser does not see uncommitted data from the test's connection, leading to empty database errors. The post suggests using a per-spec-type strategy, switching from transactions to truncation for JS specs, to ensure data visibility across connections. For Rails 7.1 and newer, a connection-shared transaction mode can replace database_cleaner, making the test connection visible to the server connection without third-party tools. The article also outlines how Mergify Test Insights detects and categorizes these errors, making it easier for developers to address cleanup-strategy mismatches and maintain stable test environments.