1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【テストコードで使用するFakerについて】

1
Last updated at Posted at 2021-03-04

テストコードを実行する際、FactryBot内で活躍するFakerについて、
ちょっとした学びがあったので備忘録として残す。

Fakerは無作為に半角数字、半角英語の組み合わせを作ってくれるもの。
パスワードのバリデーションとして、「英数字を含む」という設定が多々見受けられると思う。
基本的にはFakerをそのまま使えば問題ないが、稀に数字のみ、もしくは英語のみという組み合わせになることもある。
そうなってしまうと、バリデーションではじかれてしまうことになる。

そこでFakerに"1a"などの文字列をくっつけてやる。
そうすることで必ず"1a"という数字、英語を含む組み合わせを作ることができる。

{'1a' + Faker::Internet.password(min_length: 6)}

このような形とする。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?