Fake data generator for simple and complex structures or objects. For data generation it uses Faker gem
Add this line to your application's Gemfile:
gem 'fake_data'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fake_data
With simple schema generates fake data. Supports structure controling like how many items array should have or value presence based on probability. For random data is used (Faker gem)[https://github.com/stympy/faker].
All following rows are equivalent.
FakeData.once("Hello, my name is %{Faker::Name.name}")
=> "Hello, my name is Miss Darius Stokes"
FakeData.once("Hello, my name is %{Name.name}")
=> "Hello, my name is Ms. Santino Gutmann"
FakeData.once("Hello, my name is %{name.name}")
=> "Hello, my name is Miss Edward Kunde"
FakeData.once(
[
"I live in %{address.city}",
"My family came from %{address.country}"
]
)
=> ["I live in Winnifredshire", "And my family came from Hungary"]
FakeData.once(
{
id: "%{number.number(5)}",
name: "%{name.name}",
email: "%{internet.email}"
}
)
=> {"id"=>"70095", "name"=>"Mr. Alverta Gibson", "email"=>"[email protected]"}
Use hash with only one special control key "%{repeat(n)}"
FakeData.once(
{"%{repeat(2)}" => "I have email %{internet.email}"}
)
=> ["I have email [email protected]", "I have email [email protected]"]
From empty Array to Array with N items with repeat(0..n)
3.times do
p FakeData.once({"%{repeat(0..2)}" => "My favorite beer is: %{beer.name}"})
end
=> ["My favorite beer is Pliny The Elder", "My favorite beer is: Brooklyn Black"]
=> ["My favorite beer is: Ten FIDY"]
=> []
For empty Array returns nil
with repeat(0..n, nil: true)
FakeData.once({"%{repeat(0..1, nil: true)}" => "My favorite beer is: %{beer.name}"})
=> nil
Use hash with only one special control key "%{maybe}"
- change is 50%. maybe(20)
- chance is 20%
2.times do
FakeData.once({"%{maybe(20)}" => "I like to watch on movies with %{superhero.name}"})
end
=> "I like to watch on movies with Giant Thanos Thirteen"
=> nil
FakeData.once(
{
id: "%{number.number(5)}",
name: "%{name.name}",
age: 20,
facebook: "%{internet.url('facebook.com/profile')}",
friends: {
"%{maybe(75)}" => {
"%{repeat(2..20)}" => {
id: "%{number.number(5)}",
name: "%{name.name}",
facebook: "%{internet.url('facebook.com/profile')}",
}
}
}
}
)
After checking out the repo, run bin/setup
to install dependencies. Then, run bin/rake test
to run the tests, or guard
to run . You can also run bin/console
for an interactive prompt that will allow you to experiment. Run bundle exec fake_data
to use the gem in this directory, ignoring other installed copies of this gem.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/schovi/fake_data. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.