To find out what does factory girl do in console:
- require “factory_girl” => require the gem
- require “./factories” => require the setting of the factory girl
- include FactoryGirl::Syntax::Methods
After Step 2, we can use FactoryGirl.new, FactoryGirl.create, but we can user some syntax sugar by include ‘FactoryGirl::Syntax::Methods’
- build(:user)
- attributes_for(:user)
- attributes_for_pair(:user) =>used for relationship, it contains object_id
- build_stubbed(:user)
If you need a uniq data, you can use: sequence
factory :user do
name 'John' => do not be uniq
sequence(:email) {|n| "#{n}@example.com" => must be uniq
end
https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#configure-your-test-suite