LoginSignup
0
0

More than 1 year has passed since last update.

Fakerを使用したランダムの値の出力

Posted at

アウトプット

Fakerとは、ランダムな値を生成するGem。

(例)
% rails c

[1] pry(main)> Faker::Internet.free_email
=> "georgina@yahoo.com"

[2] pry(main)> Faker::Internet.password(min_length: 6)
=> "9DfWbC3gZsZ5cL"
(FactoryBotで記述する場合)
spec/factories/users.rb
FactoryBot.define do
  factory :user do
    email                 {Faker::Internet.free_email}
    password              {Faker::Internet.password(min_length: 6)}
    password_confirmation {password}
  end
end

学んだこと

Fakerの使い道は、例えば下記の通り。
ユーザー機能関連のテストにおいては、ユーザー名・メールアドレス・パスワード。
データ機能関連のテストにおいては、テキスト・画像。

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