跳到正文
DEV Community· Caio Andrade·· 12 天前AI 評分45

AI 令 Fixtures 相對 Factories 優勢懸殊

AI made fixtures unfair to factories

AI 導讀

作者以 AI 將大量使用 factories 的 Rails 測試規格改寫為 fixtures,令相關規格通常快約 10x;作者稱 8x 是穩妥結果,理想情況可達 15x。Fixtures 原本較難編寫和管理,作者認為 AI 大幅降低了這項成本,令 fixtures 相較 factories 更具優勢。

正文

Caio Andrade

I've been thinking a lot about one of the oldest discussions we've had as Rails developers: factories or fixtures?

At some point, I think we reached a consensus. Factories are easy for devs to manage. They're familiar and simple, and that's good. But they have a lot of problems, especially with deep nesting. Factories get slower and slower if people aren't careful, and let's just admit it, people very often aren't.

Fixtures have always been annoying to manage. They're written in a very data-heavy way, so they read more like data than objects. That brings its own problems, and they're annoying to write. But fixtures have always been super fast to run.

In a world where AI exists, I think fixtures now have such a massive edge over factories that it's not even fair anymore. The annoying part of dealing with fixtures is gone. You can just outsource it to AI.

That's what I've been doing at my current job. I've been going through specs that spend pretty much 90% of their time in factories and changing them to fixtures.

And then with very little cost those specs got generally 10x faster, sometimes even more. 8x is a certainty. 15x on a nice case.

And most of this has been me telling an AI, "Just rewrite this shit with fixtures." Goodbye.

It's such a massive win for a really low cost. More devs should be doing this.

來源:DEV Community · dev.to