Faking it with Machinist
 Create realistic, repeatable, datasets for testing and
                      development




Ada...
Why?
• Make tests shorter, simpler
• Dependable development data
• Easy to make changes
• rake db:reset calls db/seeds.rb
...
Setup



          The Resets make
        them start over after
           each rollback
Machinist
            http://github.com/notahat/machinist
“create test data within your tests. It generates data for the
 ...
make & make_unsaved
Both generate the object, but make_unsaved doesn’t
         call valid? or save or create, ect.
blueprint.rb Shams
Sham: random but repeatable unique attributes values
a blueprint
        Call shams to generate data

                      or you can
                     specify fields
     ...
Creating
# make a generic User instance
User.make
User.make_unsaved
Post.make(:city => "Atlanta")

# make a named instance...
AR Inheritance


Simple, or you can use over rides like before.
          I like writing test helpers
Faker
                         http://faker.rubyforge.org/



                             A port of Perl‘s
              ...
How much Fake?




   Notice the uniques on the shams, this is a gotcha
     after you generate all possible (or run out o...
Faker Example
seeds.rb



Remember Account generated users also.
  so we have 100 users with accounts
         in our development.rb
  t...
Adam Dill
  Senior Developer
 www.isotope11.com
adam@isotope11.com
Upcoming SlideShare
Loading in …5
×

Machinist

1,951 views
1,863 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,951
On SlideShare
0
From Embeds
0
Number of Embeds
18
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Machinist

    1. 1. Faking it with Machinist Create realistic, repeatable, datasets for testing and development Adam Dill www.isotope11.com
    2. 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. 3. Setup The Resets make them start over after each rollback
    4. 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. 5. make & make_unsaved Both generate the object, but make_unsaved doesn’t call valid? or save or create, ect.
    6. 6. blueprint.rb Shams Sham: random but repeatable unique attributes values
    7. 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. 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")
    9. 9. AR Inheritance Simple, or you can use over rides like before. I like writing test helpers
    10. 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. 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)
    12. 12. Faker Example
    13. 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. 14. Adam Dill Senior Developer www.isotope11.com adam@isotope11.com

    ×