Using factories
Factories allows you to extract common functionality from blueprints building. For example let’s say you have:
Instead of all that you could extract a factory and all the code would look like this:
Where :create
is a strategy that this factory is defined for. This can then be shortened
even more by:
This same factory would even work for subclasses of Fruit! So you could write factories for your own ORMs. For examples see ActiveRecord factories and Mongoid factories
ORM factories
Since they are so widely used, BlueprintsBoy provides factories for ActiveRecord (>= 3.1) and Mongoid (>= 2.0) out of the box.