LoginSignup
1
1

More than 5 years have passed since last update.

Ruby Gem Fakerでテスト用の人名を作成する

Posted at

伊藤淳一さんの チェリー本 を読んでいたら、テスト用データを作るGemの faker が例で出ており、使ってみると面白そうだったのでメモしておきます。
こちらの記事も参考にさせていただきました。ありがとうございます。
Fakerでダミーデータを生成する

GemFile
source "https://rubygems.org"  
gem 'faker'
install
$ bundle install --path vendor/bundle
faker_sample.rb
require 'bundler/setup'
require 'faker'

def print_names
    10.times do 
        puts Faker::Name.name
    end
end

# 日本人名
Faker::Config.locale = :ja
print_names

# 英語人名
Faker::Config.locale = :en
print_names

# 中国人名
Faker::Config.locale = 'zh-CN'
print_names
  • 結果
佐々木 空
岩崎 彩花
平野 裕子
藤本 楓
丸山 茜
渡辺 誠
井上 亮太
原 碧
河野 悠斗
竹内 太一
Romeo Wuckert
Fran Lakin
Floy Bradtke
Cuc Oberbrunner
Harold Reynolds
Clarence Okuneva
Mose Labadie
Enrique McLaughlin
Wilton Gutmann
Grover Goyette PhD
侯正豪
龙鹏飞
邱思源
白绍齐
段锦程
武熠彤
汪明杰
廖炎彬
钱瑾瑜
徐擎苍
1
1
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
1