Friday, July 31, 2009

Make Faker work with Factory Girl

If you use the code below, faker will not churn out unique names

Factory.define :user do |u|
u.first_name Faker::Name.first_name
u.last_name Faker::Name.last_name
end

However putting curly braces around faker makes it work!

Factory.define :user do |u|
u.first_name { Faker::Name.first_name }
u.last_name { Faker::Name.last_name }
end

9 comments:

michelson said...

save me hours, thanks!

I hate sweating said...

Thankss

arnodmental said...

Same for me, thanks a lot, I had tried :

Factory.define(:user) do |u|
u.firstname Proc.new { Faker::Name.first_name }
end


But did not return the actuel Proc result.

Carl said...

Thanks so much!

Gokul said...

thanks for sharing ...

Fitria Rahmaani said...

thanks a lot :D

Ranska said...

you're my hero !!!

Ranska said...

you're my hero !!!

Laurens Vandenberghe said...

Thanks! However it's not quite clear to me what makes it work with the curly braces.... any chance someone can explain?

Blog Archive