Permalink
Browse files

Don't actually advocate using Faker to generate test data

  • Loading branch information...
1 parent 4e2b7e0 commit b6692b61f89d6e81796c1f6dff7f72bc75145db1 @joshuaclayton joshuaclayton committed Jul 7, 2012
Showing with 6 additions and 6 deletions.
  1. +6 −6 GETTING_STARTED.md
View
@@ -690,7 +690,7 @@ Instead of creating a child factory that added additional attributes:
```ruby
FactoryGirl.define do
factory :application_user, parent: :user do
- full_name { Faker::Name.name }
+ full_name "Jane Doe"
date_of_birth { 21.years.ago }
gender "Female"
health 90
@@ -703,7 +703,7 @@ You could modify that factory instead.
```ruby
FactoryGirl.modify do
factory :user do
- full_name { Faker::Name.name }
+ full_name "Jane Doe"
date_of_birth { 21.years.ago }
gender "Female"
health 90
@@ -758,14 +758,14 @@ sequence(:name) {|n| "person#{n}@example.com" }
factory :user do
ignore do
- name { Faker::Name.name }
+ name "Jane Doe"
end
email
initialize_with { new(name) }
end
-FactoryGirl.build(:user).name # Bob Hope
+FactoryGirl.build(:user).name # Jane Doe
```
Notice that I ignored the `name` attribute. If you don't want attributes
@@ -793,7 +793,7 @@ For example:
```ruby
factory :user do
ignore do
- name { Faker::Name.name }
+ name "John Doe"
end
initialize_with { User.build_with_name(name) }
@@ -809,7 +809,7 @@ factory :user do
comments_count 5
end
- name { Faker::Name.name }
+ name "John Doe"
initialize_with { new(attributes) }
end

5 comments on commit b6692b6

@mike-burns
Member

👍

@croaky
Member
croaky commented on b6692b6 Jul 7, 2012

Agreed.

@akasper

Wait, why?

@joshuaclayton
Member

@akasper It can lead to things silently passing or failing when they shouldn't. If you're dealing with data that must be unique, FactoryGirl has a sequence that's perfect for this:

factory :user do
  sequence(:email) { |n| "person#{n}@example.com" }
end
@jferris
Member

Using randomized test data will often lead to erratic tests. It will create failure scenarios that are difficult to reproduce. This is why test runners that allow randomized test order allow you to specify the seed: otherwise, you wouldn't be able to reliably reproduce the failure from a specific test order.

You can remove the erratic test risk from Faker by using a consistent seed in your tests, but generating names that way for test data offers no advantage over static strings or simple sequences.

Please sign in to comment.