paulelliott / fabrication

This project has moved to GitLab! Please check there for the latest updates.
https://gitlab.com/fabrication-gem/fabrication
MIT License
998 stars 97 forks source link

Where to extract methods ? #300

Closed dbesserman closed 7 years ago

dbesserman commented 7 years ago

I'd like to extract methods from fabricators to a helper. How should I go about that ?

paulelliott commented 7 years ago

That is a great question! Could you give me an example of what you're trying to do? Pseudo-code is fine.

dbesserman commented 7 years ago

Let's say I have a method that generates a random string that I'd like to share across a few fabricators. Is there a natural place for that method ?

paulelliott commented 7 years ago

I always recommend using ffaker in conjunction with fabrication. For example,

Fabricator(:company) do
  name { FFaker::Company.name }
end

It has lots of ipsums and other random word generators. Pretty much any random data you could possibly need. Just wrap it in a block as I did above when you pass it to the attribute and it will work as expected.