The capabilities are introduced by this tutorial of factory-girl . We are going to begin with a easy factory for the hypothetical consumer model and slowly enhance it. This guide may well not protect every aspect of factory-girl , but should act as a good kick off point.
An Individual Factory
Why don’t we begin with a easy user factory, once we continue, we are going to carry on changing this factory to incorporate functionality and show just exactly exactly how factory-girl works.
If we require a person item now, we could just ask factory-girl to construct one for people. Which is awesome, although not very helpful yet. Most of the things we get back from factory-girl now have same home values.
The build api enables us to pass through characteristics to bypass standard ones, therefore we may do:
Once more, this can be handy, yet not invaluable, it needs us to help keep supplying an email that is new each and every time you want to produce a person model.
factory-girl has a remedy: sequences. As opposed to supplying a value that is hardcoded we are able to inform factory-girl to alternatively work with a series. A small modification into the model-factory meaning:
Now we have an email that is new each time we ask factory-girl for a person example:
Better! let us include title and about attributes for the consumer models:
This will work fine, exactly what for those who have a few test instances that anticipate going to be actually a paragraph? Or in other words have individual names that look a little practical in place of user title 1 ? factory-girl provides another goodie that individuals may use for a far more ‘realistic’ data: chancejs . You can easily find out about chancejs right right here. Continue reading