LoginSignup
0
0

More than 1 year has passed since last update.

【Ruby on Rails】Factorybotでのインスタンス生成方法

Last updated at Posted at 2022-11-14

フォルダーの作成

「spec」フォルダー内に「factories」フォルダーを作成

ファイルの作成

「factories」内に「モデル名(複数形).rb」ファイルを作成。

例えば、

「spec/factories/users.rb」

ファイルに以下記載

以下、例

spec/factories/users.rb
FactoryBot.define do
  factory :user do
    name {Faker::Name.last_name}
    email {Faker::Internet.free_email}
    password {Faker::Internet.password(min_length: 6)}
    password_confirmation {password}
  end
end

データ型の選び方

公式ページを参照
https://github.com/faker-ruby/faker

#techcamp136期

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0