Skip to content
Daisuke Nashiro edited this page Apr 26, 2019 · 6 revisions

Who does this gem do?

Ok. You need some test data.

Let's say you are creating a model:

  • Project. Project has the following attributes:
    • name
    • no

You'd have to think up a name and no. That can get pretty tedious.

Let Ffaker create those names for you, based on the data stored in the gem.

When you run the test you might get a Project: "Donald" from "1600 PA avenue" or a different name depending on what the gem selected.

Example of FFaker in use

FactoryBot.define do
  factory :project do
    name { FFaker::Name.name }
    no { FFaker::Product.model }
  end
end

I can then do something like this:

   project_just_created = create(:project)

   project_just.created.name ## this could return any name. e.g. "Haris Pilton" depending on what the gem randomly selects.

Good luck and I hope this helps you.

Clone this wiki locally