1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
A library for setting up Ruby objects as test data.
Find a file
2008-05-31 10:46:33 -07:00
lib Added activesupport as a dependency 2008-05-30 17:10:55 -07:00
test Renamed #attributes to #attributes_for 2008-05-28 22:22:48 -04:00
.gitignore Added a schema to test with 2008-05-28 18:28:02 -04:00
Rakefile Added a Gemspec and a Rake task to build the gem 2008-05-31 10:46:33 -07:00
README Cleaned up documentation and the README 2008-05-29 01:11:33 -04:00

= factory_girl

== Defining factories

  # This will guess the User class
  Factory.define :user do |u|
    u.first_name 'John'
    u.last_name  'Doe'
    u.admin false
  end

  # This will use the User class (Admin would have been guessed)
  Factory.define :admin, :class => User do |u|
    u.first_name 'Admin'
    u.last_name  'User'
    u.admin true
  end

It is recommended that you create a test/factories.rb file and define your
factories there. This file can be included from test_helper or directly from
your test files. Don't forget:
  require 'factory_girl'

== Using factories

  # Build and save a User instance
  Factory(:user)

  # Build a User instance and override the first_name property
  Factory.build(:user, :first_name => 'Joe')

  # Return an attributes Hash that can be used to build a User instance
  attrs = Factory.attributes_for(:user)