【Ruby on Rails, Rspec】Factorygirlでデータを作成する
- createだとデータベースに保存される
@user = FactoryGirl.create(:user)
User id: 2, email: "MyString", password: "MyString", created_at: "2012-05-04 06:57:38", updated_at: "2012-05-04 06:57:38"
- buildだとデータベースに保存されないので、idやcreated_atはnilになる。
@user = FactoryGirl.build(:user)
User id: nil, email: "MyString", password: "MyString" created_at: nil, updated_at: nil
- build_stubbedだとデータベースに保存されないがidは登録される
@user = FactoryGirl.build_stubbed(:user)
User id: 1002, email: "MyString", password: "MyString", created_at: nil, updated_at: nil