608.620.5104 | info@tenforward.consulting
Psst! We're hiring!

Our inclusive, feminist office is looking to hire for the following position:

Learn more about the job at our careers page, and learn more about Ten Forward as a company on our mission and vision page and about us page! 

When testing in Rails, don't use the gem Faker for things that need to be unique

Published March 30, 2016

You'd think it unlikley that Faker::Internet.domain_word would return the same value twice, but when you're in a world of continuous integration where your tests get run all the time, it absolutely happens. (The same thing happens with Faker::Internet.email.) Faker has its uses, but not when you need unique values.

Instead, use a sequence, and thus guarantee that your tests won't randomly fail:

FactoryGirl.define do
factory :user do
sequence(:email) { |n| "email#{n}@example.com" }

Author details

Brian Samson