Machinist is a Ruby gem that helps create realistic, repeatable test data by generating fake values for fields that are not important to the test, and constructing any necessary associated objects, allowing tests to be shorter, simpler, and for development data to remain dependable as changes are made. It extends ActiveRecord with make and make_unsaved methods to generate objects without saving for testing purposes, and uses blueprints and sham values to produce randomized yet repeatable unique attributes.
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
Machinist
1. Faking it with Machinist
Create realistic, repeatable, datasets for testing and
development
Adam Dill www.isotope11.com
2. Why?
• Make tests shorter, simpler
• Dependable development data
• Easy to make changes
• rake db:reset calls db/seeds.rb
• works great in console for playing with
requests: u = user.make
3. Setup
The Resets make
them start over after
each rollback
4. Machinist
http://github.com/notahat/machinist
“create test data within your tests. It generates data for the
fields you don't care about, and constructs any necessary
associated objects”
Like (and inspired by) Factory Girl, but with a cleaner DSL
Extends active_record with make, make_unsaved
5. make & make_unsaved
Both generate the object, but make_unsaved doesn’t
call valid? or save or create, ect.
7. a blueprint
Call shams to generate data
or you can
specify fields
you always
to be the
same
Or create named blueprints,
they inherent from their
master blueprint
8. Creating
# make a generic User instance
User.make
User.make_unsaved
Post.make(:city => "Atlanta")
# make a named instance
User.make(:inactive_bob)
User.make_unsaved(:inactive_bob)
# or override a field
User.make(:city => "Atlanta")
10. Faker
http://faker.rubyforge.org/
A port of Perl‘s
Data::Faker library that
generates fake data.
How much Fake could a faker fake if a faker could ... forget it
11. How much Fake?
Notice the uniques on the shams, this is a gotcha
after you generate all possible (or run out of
Faker data) then it will error out.
if this is a problem, add an index (see the email field)
13. seeds.rb
Remember Account generated users also.
so we have 100 users with accounts
in our development.rb
that aside from random generators
are the _exact_ same every time.
Its also fast
14. Adam Dill
Senior Developer
www.isotope11.com
adam@isotope11.com