The more your application gets, the more benefits you get from factories.
Your solution is great for 2-3 models. But let's say you have an article model in which you need valid users for testing. You now have 2 files where you define @attr for users. Now imagine that there are even more models that users need, such as comments, roles, etc. It is getting messy.
It is more convenient to use factories. You can define several prototypes by default. As admin user, regular user, unregistered user, etc.
In addition, the code is DRY, so if you add a new required field, you can add it once to your factory, and you're done.
So, the answer is this: basically they are the same, but the larger your application, the more you need a way to manage all your prototypes.
source share