 { |n| "example#{n}@mail.com" }
sequence(:age)
end
Associations
Associations are used by name:
maker :user do
posts
comments 4 # You can customize the number of records
end
maker :post do
user
end
maker :comment do
user
end
Aliases
The aliases are important when there is the need of context:
maker :user, aliases: :author do
comments
end
maker :post, aliases: :comment do
title
end
Dependent attributes
If you need to use some logic that depends of another attribute you can use a block or sequence:
maker :user do
name 'example'
email { "#{name}@mail.com" }
sequence(:username) { |n| "#{name}-#{n}" }
end
Callbacks
The available callbacks are before(:build), before(:create), after(:build) and after(:create):
maker :user do
after(:build) { |u| u.name = 'sample' }
end
You can declare global callbacks in your test or spec helper as well:
Makers.configure do
after(:create) do |object|
log object.errors unless object.valid?
end
end
Credits
This gem is maintained and funded by mmontossi.
License
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.