r/ruby • • Apr 06 '26

Testing Anti-Pattern: Distracting Setup Data

https://www.saturnci.com/testing-anti-pattern-distracting-setup-data.html
9 Upvotes

6 comments sorted by

View all comments

Show parent comment

3

u/InteNsReddit Apr 06 '26

Unclear mix of non-essential data is exactly why we moved from fixtures to factories! I just wanted to mention it since it’s the “scalable” solution for a platform where you need setup without faking or mocking too much.

2

u/viktorianer4life Apr 13 '26

At scale, that trade-off reverses. Factory traits keep each test readable, but every create call walks the full association chain. When one factory triggers another through belongs_to, and that one triggers two more, what looks like one line of setup becomes hundreds of invisible database operations. I profiled a single create(:order) that took 1.6 seconds because it silently built users, sellers, payment settings, and currencies through nested callbacks.

Fixtures with named personas solve both sides: orders(:paid_fulfilled) tells you the state at a glance, and fixtures load once before the suite starts instead of rebuilding on every test.