Skip to content

Instantly share code, notes, and snippets.

@awesome
Created April 17, 2012 22:56
Show Gist options
  • Save awesome/2409675 to your computer and use it in GitHub Desktop.
Save awesome/2409675 to your computer and use it in GitHub Desktop.
factory girl build vs create
#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
@DutchTraveller
Copy link

@diegosouza
Copy link

When you say "saved object" you mean persisted object, like a Rails model?

@olitreadwell
Copy link

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