Making use of the Faker gem

Professional League of Legends player “Faker”. He is widely considered the best LoL player

The Faker gem is a useful ruby gem that produces data at random, this can be useful when you’re in need of data, but don’t want to use an API. Imagine you need to fill out users with E-mails or if they need different data for seeding purposes? This ends up being tedious to hard code and implementing an API can be difficult.

This is where the gem comes in, Faker is an open-source gem for generating fake data. Say you’re trying to work on an API involving Japanese media (or Anime, but you get the idea). Faker would have you covered, being able to add real data to your library.

An example of the options given in the Faker gem file

Now that you’ve seen how the Faker gem works, you might be wondering; how do I get started? For starters, you can find the gemfile here. Make sure your gemfile includes gem “faker”

Here's what my gemfile looked like

After that, you can begin installing Faker by running the following:

gem install faker

Now that the Faker gem is installed, you can play around with it in your seeds.rb file. However, take note that the data is generated at random, meaning that you will not be given the same data every time you run your database. Hence why Faker giving out “fake” data is the purpose of this ruby gem.

Here’s an example of what a seed file could look like with the Faker gem

After implementing your own seeds, make sure to run rake db:seed in your terminal. After that, your randomly generated data should be good to go! Be sure to look through the different generators Faker has to offer a few times. It took me a few reads before I noticed that even League of Legends was an option for data (this being the person I referenced the gem name to earlier). Below will be a few more examples of topics you can cover.

Examples of games from the Faker gem
Examples within the League of Legends topic in the Faker gem

By now, I hope you’ve seen the power of the Faker gem and how you can make use of it. It was a lifesaver on one of my projects, as I needed to seed random user data and review data; Faker proved to be perfect for this occasion. Happy coding :)





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

WeNudge: Stop and Think

My Salesforce Journey: Volume 1

9 Must-Know PCB Assembly (PCBA) Equipment

When and Why should we calculate Big-O?

Cloud Tagging — Strategic Practices

Not all Technical Debt is the Same

Get Beautiful Coverage Reports in your Android Projects!

ARES Plugin — How to have allure report with actual info about device

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Johnny Cao

Johnny Cao

More from Medium


New World Chaos, divine and profane

Should you do FedRAMP High and IL4 at the same time?

Super Mario Maker 2, The Black Hole Glitch, and Unwritten Rules