Created
April 17, 2012 22:56
-
-
Save awesome/2409675 to your computer and use it in GitHub Desktop.
factory girl build vs create
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://archived.rpheath.com/posts/411-how-to-use-factory-girl-with-rspec | |
describe Whatever do | |
before(:each) do | |
@user = Factory.build(:user) # returns an unsaved object | |
@user = Factory.create(:user) # returns a saved object | |
@user = Factory(:user) # shortcut for Factory.create() | |
end | |
it "should be a dumb test to show usage" do | |
@user.name.should == "Ryan Heath" | |
@user.email.should == "[email protected]" | |
end | |
end |
When you say "saved object" you mean persisted object, like a Rails model?
This StackOverflow Q/A does a great job of answering this question as well
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
link doesn't work any more:
http://archived.rpheath.com/posts/411-how-to-use-factory-girl-with-rspec