Open Source ProjectsCode that Might be Useful to You

Talks I've GivenOn Technologies and Ideas

ThoughtsWhere I Sometimes Write Things

Resume If You Believe In Those

Follow Me On

GitHubIf coding is your thing

TwitterIf you tweet

Autoloading factory_girl definitions

I’d like to point out a feature that silently made it into factory_girl as of 1.1.4: autoloading of factory definitions.

If you create test/factories.rb, spec/factories.rb, they will automatically be required, making your factories available to your tests or specs.

Additionally, you can create directories named test/factories and spec/factories, and any .rb files will be required as well. I generally prefer this way, and name factories like urmodel_factory.rb, such that fuzzy finding files makes it easy to open up a specific factory.

This functionality was part the factory_girl_on_rails plugin I wrote several months ago before there was any autoloading. Once I got annoyed by having to install a plugin in addition to a gem, I found a way to do it inside of factory_girl herself, and you can now benefit from that work.

Relatedly, you can consider factory_girl_on_rails deprecated in favor of the built-in factory_girl functionality.

comments powered by Disqus