Navigation Menu

Skip to content

Commit

Permalink
Documentation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Jul 1, 2011
1 parent b6860ba commit 4d83729
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions GETTING_STARTED.md
Expand Up @@ -77,6 +77,14 @@ If repeating "FactoryGirl" is too verbose for you, you can mix the syntax method
include Factory::Syntax::Methods
end

This would allow you to write:

describe User, "#full_name" do
subject { create(:user, :first_name => "John", :last_name => "Doe") }

its(:full_name) { should == "John Doe" }
end

Lazy Attributes
---------------

Expand All @@ -85,6 +93,7 @@ Most factory attributes can be added using static values that are evaluated when
factory :user do
# ...
activation_code { User.generate_activation_code }
date_of_birth { 21.years.ago }
end

Dependent Attributes
Expand Down Expand Up @@ -157,10 +166,6 @@ You can also assign the parent explicitly:
approved true
end

approved_post = FactoryGirl.create(:approved_post)
approved_post.title # => 'A title'
approved_post.approved # => true

As mentioned above, it's good practice to define a basic factory for each class with only the attributes required to create it. Then, create more specific factories that inherit from this basic parent. Factory definitions are still code, so keep them DRY.

Sequences
Expand Down Expand Up @@ -231,20 +236,20 @@ Examples:
after_build { |user| generate_hashed_password(user) }
end

Note that you'll have an instance of the user in the block. This can be useful.
Note that you'll have an instance of the user in the block. This can be useful.

You can also define multiple types of callbacks on the same factory:

factory :user do
after_build { |user| do_something_to(user) }
after_build { |user| do_something_to(user) }
after_create { |user| do_something_else_to(user) }
end

Factories can also define any number of the same kind of callback. These callbacks will be executed in the order they are specified:

factory :user do
after_create { this_runs_first }
after_create { then_this }
after_create { then_this }
end

Calling FactoryGirl.create will invoke both after_build and after_create callbacks.
Expand Down Expand Up @@ -281,4 +286,3 @@ Users' tastes for syntax vary dramatically, but most users are looking for a com
end

User.make(:name => 'Johnny')

0 comments on commit 4d83729

Please sign in to comment.