LoginSignup
(一)Trend
(二)Question
(三)Official Event
(四)Official Column
(五)signpostCareer
(六)Organization
62
Go to list of users who liked
62
info
More than 5 years have passed since last update.
@kyanny(Kensuke Nagae)
Faker を i18n locale :ja で使うときは Faker::Config.locale を :en にセットしなおすべし
●Ruby
Posted at
Faker は各種 locale に対応しているので Rails アプリなどで default locale を :ja にセットすると人名のダミーデータが日本語化されたりして便利なのだけど Faker::Internet.email がぶっ壊れてテストデータの email バリデーションエラーが出まくってハマった。
default locale :en で使う場合
問題無し。普通はこういう状態を期待する。
require 'i18n'
I18n.locale # => :en
require 'faker'
Faker::Config.locale # => :en
Faker::Internet.email # => "sanford@jacobsonjohns.com"
I18n.locale = :ja にセットして使う場合
Faker の locale も :ja になり、 email アドレスの local part / domain part が壊れる (内部的に日本語で﹃美咲.清水@美咲.com﹄みたいなデータが作られた上で ascii 範囲外の文字列が削除されていると予想)
require 'i18n'
I18n.locale # => :en
I18n.locale = :ja
I18n.locale # => :ja
require 'faker'
Faker::Config.locale # => :ja
Faker::Internet.email # => ".@.com"
i18n.locale = :ja した上で Faker::Config.locale = :en にセットしなおす
期待した振る舞いに戻る。
require 'i18n'
I18n.locale # => :en
I18n.locale = :ja
I18n.locale # => :ja
require 'faker'
Faker::Config.locale # => :ja
Faker::Config.locale = :en
Faker::Config.locale # => :en
Faker::Internet.email # => "ransom_blanda@auer.name"
62
Go to list of users who liked
62
comment0
Go to list of comments
Register as a new user and use Qiita more conveniently
(一)You get articles that match your needs
(二)You can efficiently read back useful information
(三)You can use dark theme
What you can do with signing up
Sign upLogin
62
Go to list of users who liked
62
How developers code is here.
Guide & Help
Contents
SNS
Our service
Company