public
Description: Fixture replacement for focused and readable tests.
Home | Edit | New

Usage

Add factories to test/factories.rb, spec/factories.rb file, or under a test/factories or spec/factories directory:

Factory.define :user do |f|
  f.first_name 'John'
  f.last_name  'Doe'
end

Factory.define :admin, :parent => :user do |f|
  f.admin true
end

Once your factories are defined, you can use them in the following ways:

# Saved instance
user = Factory(:user)

# Unsaved instance
user = Factory.build(:user)

# Attribute hash
user_attributes = Factory.attributes_for(:user)

# Stubbed object
user_stub = Factory.stub(:user)

# Override attributes
user = Factory(:user, :first_name => 'Joe')
Last edited by jayshepherd, Wed Aug 12 08:00:23 -0700 2009
Home | Edit | New
Versions: