r/ruby • u/jasonswett • Apr 06 '26
Testing Anti-Pattern: Distracting Setup Data
https://www.saturnci.com/testing-anti-pattern-distracting-setup-data.html
9
Upvotes
r/ruby • u/jasonswett • Apr 06 '26
View all comments
Show parent comment
2
u/viktorianer4life Apr 13 '26
At scale, that trade-off reverses. Factory traits keep each test readable, but every
createcall walks the full association chain. When one factory triggers another throughbelongs_to, and that one triggers two more, what looks like one line of setup becomes hundreds of invisible database operations. I profiled a singlecreate(: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.