Questions tagged [faker]

An extension or library used in certain programming languages or frameworks (namely Ruby or Yii2) for generating fake data for debug purposes and testing.

In Ruby, Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc.

In Yii2, Faker can generate random strings (like name, address, phone number or anything), random numbers, keys or harshes as well as long sentences of fake text. It can be accessed in OOP style.

A PHP library is available for Faker that is used in some frameworks such as Laravel.

703 questions
15
votes
2 answers

Change faker gem phone number format

Is there a way to control the format of the Phone number generated by faker? When I call: Faker::PhoneNumber.cell_phone.to_i I end up getting the wrong value. I also would like to not have extensions.
rafamvc
  • 8,227
  • 6
  • 31
  • 34
14
votes
5 answers

Generate an array with random data without using a for loop

I am using the faker.js library to generate random data and I have a couple of factory functions that generate a series of user data: const createUser = () => { return { name: faker.name.findName(), email: faker.internet.email(), …
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
13
votes
2 answers

How to use lazy_attribute with Faker in Factory Boy

Context: I have a model with two dates, I want to use factory.Faker for both of them but the second date should always be greater that the first one. I tried this: Model excerpt: class Event(models.Model): execution_start_date =…
diegueus9
  • 29,351
  • 16
  • 62
  • 74
12
votes
4 answers

Rspec controller test failing with Apostrophe Character?

Right now I have unit tests that are failing using the "Faker" Company Name. it seems like the expect(response.body).to match(@thing.name) is whats getting messed up. When looking at the error, the Faker Company names will sometimes have things like…
msmith1114
  • 2,717
  • 3
  • 33
  • 84
11
votes
1 answer

In Factory Boy, how to join strings created with Faker?

I want to use Factory Boy and its support for Faker to generate strings from more than one provider. e.g. combining prefix and name: # models.py from django.db import models class Person(models.Model): full_name =…
Phil Gyford
  • 13,432
  • 14
  • 81
  • 143
11
votes
4 answers

Laravel faker generate gender from name

What is the optimum way of generating gender using faker, having generated a name so that the gender matches the name return [ 'name' => $faker->name, 'email' => $faker->safeEmail, 'username' => $faker->userName, 'phone' =>…
Morris Mukiri
  • 113
  • 1
  • 2
  • 10
11
votes
2 answers

How to generate latitude, longitude info using Faker from Laravel seeder?

I am trying to use Faker in a Laravel seeder. Here is how my seeder class look like
Jaylen
  • 39,043
  • 40
  • 128
  • 221
11
votes
3 answers

How to seed database in yii2?

I am new to Yii framework. I want to seed my database like it can be done in Laravel framework using Faker. I tried this http://www.yiiframework.com/forum/index.php/topic/59655-how-to-seed-yii2-database/ but it does not provide much details. I would…
Faisal Qureshi
  • 231
  • 1
  • 2
  • 9
11
votes
1 answer

How to change generated text's language in fzaninotto/Faker?

In Laravel I use Faker. (fzaninotto/Faker) Can't change locale(language) of generated texts. My code: use Faker\Factory as Faker; class MySeeder extends Seeder { public function run() { $faker = Faker::create('ru_RU'); …
YanDatsiuk
  • 1,885
  • 2
  • 18
  • 30
10
votes
2 answers

How to set length for python Faker fields

I am trying to set up UserFactory using DjangoModelFactory from factory_boy and Faker. Here is my code. fake = Faker('uk_UA') class UserFactory(DjangoModelFactory): class Meta: model = User username = fake.user_name first_name…
Myroslav Hryshyn
  • 716
  • 7
  • 18
10
votes
3 answers

Should we be using Faker in Rails Factories?

I love Faker, I use it in my seeds.rb all the time to populate my dev environment with real-ish looking data. I've also just started using Factory Girl which also saves a lot of time - but when i sleuth around the web for code examples I don't see…
Huw
  • 635
  • 11
  • 25
10
votes
1 answer

Use Faker gem to generate correlated city, postal code, country code values

Is there a way to get the Faker gem to generate 'correlated' city and country code values? For example, Vancouver, CA Minneapolis, MN I'm doing this: FactoryGirl.define do factory :location do ... city {Faker::Address.city} …
craig
  • 25,664
  • 27
  • 119
  • 205
9
votes
2 answers

Custom faker provider for usage with factory boy and pytest

I am attempting to add some custom faker provider to use with factory_boy and pytest. I put the provider in faker_providers/foo.py/Provider. In my factories.py file, I have to import foo.py and then register by…
dephiros
  • 353
  • 2
  • 7
9
votes
4 answers

Using Python Faker generate different data for 5000 rows

I would like to use the Python Faker library to generate 500 lines of data, however I get repeated data using the code I came up with below. Can you please point out where I'm going wrong. I believe it has something to do with the for loop. Thanks…
Conrad Addo
  • 424
  • 1
  • 5
  • 15
9
votes
4 answers

Faker generating strange phone numbers?

So I'm creating a database with Laravel and seeding it, and I ran into an issue where it generates a phone number as follows: (635) 889-5802 x45134. This causes issues by exceeding the desired length of the database column. So my questions are: On…
dluxcru
  • 397
  • 1
  • 5
  • 16
1
2
3
46 47