factory_bot 6.3.0

We are thrilled to announce the release of factory_bot 6.30!

The factory_bot library is a tool for setting up Ruby objects as test data, and has become a vital part of any test interacting with ActiveRecord.

The 6.3.0 release saw tons of internal improvements thanks to Andrii Konchyn, Daniel Colson, Daniel Nolan, Stefanni Brasil, and Yudai Takada. Thank you to each of them for the invisible work that keeps factory_bot running!

On the docs side, you likely saw the work I put into updating the docs. I’d like to shout out Berkan Ünal, Edmund Korley, Glauco Custódio, Jonas S, Lawrence Chou, Mark Huk, Robert Fletcher, Sara Jackson, and Stefanni Brasil for their improvements to the book, the README, and the release notes. Documentation is a vital part of a library, and they deserve all the recognition they can get for their help.

Visible changes

This release contains three user-visible changes.

The did_you_mean gem ships with Ruby; it’s what offers suggested method names when you get a NoMethodError. The factory_bot library makes use of it to offer suggestions if the factory name is missing. In Ruby 3.2, the interface for this library changed; thankfully, Daniel Colson noticed and patched it. This means factory_bot will work on Ruby 3.2.

When creating objects from factories, you can use the stub strategy (build_stubbed) to get a dummy object. This object quacks like an ActiveRecord object. Benjamin Fleischer noticed that the #destroyed? method returned nil, not false, whereas in ActiveRecord it returns only true or false. Thanks to Benjamin for fixing that in factory_bot. This means that factory_bot is actually compatible with ActiveRecord.

And finally, Sean Doyle added a hook that triggers an ActiveSupport notification whenever a factory definition is fully evaluated and ready to use: factory_bot.compile_factory. He has plans to use this from the factory_bot_rails gem, but it’s also available to anyone for all your hook needs.