Skip to content

Latest commit

 

History

History
43 lines (34 loc) · 763 Bytes

factory-girl-sequences.md

File metadata and controls

43 lines (34 loc) · 763 Bytes

FactoryGirl Sequences

FactoryGirl sequences are often used inline for unique values such as emails:

factory :user do
  sequence(:email) { |n| "person#{n}@example.com" }
end

However, a sequence can be defined on its own

FactoryGirl.define do
  sequence :email do |n|
    "person#{n}@example.com"
  end
end

That means it can be invoked outside the context of a factory

> FactoryGirl.generate :email
=> "[email protected]"
> FactoryGirl.generate :email
=> "[email protected]"

Or it can be used as a shared sequence across multiple factories

factory :customer do
  ...
  email
end

factory :admin do
  ...
  email
end