Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v2.0.0.beta2
Fetching contributors…

Cannot retrieve contributors at this time

86 lines (65 sloc) 2.901 kb

Machinist 2

Fixtures aren't fun. Machinist is.


Machinist makes it easy to create objects within your tests. It generates data for the attributes you don't care about, and constructs any necessary associated objects, leaving you to specify only the attributes you do care about in your tests. For example:

describe Comment do
  it "should not include spam in the without_spam scope" do
    # This will make a Comment, a Post, and a User (the author of the
    # Post), generate values for all their attributes, and save them:
    spam = Comment.make!(:spam => true)

    Comment.without_spam.should_not include(spam)

You tell Machinist how to do this with blueprints:

require 'machinist/active_record'

User.blueprint do
  username { "user#{sn}" }  # Each user gets a unique serial number.

Post.blueprint do
  title  { "Post #{sn}" }
  body   { "Lorem ipsum..." }

Comment.blueprint do
  email { "commenter-#{sn}" }
  body  { "Lorem ipsum..." }

Check out the documentation for more info.


Machinist is maintained by Pete Yandell (, @notahat)

Other contributors include:

Marcos Arias, Jack Dempsey, Jeremy Durham, Clinton Forbes, Perryn Fowler, Niels Ganser, Jeremy Grant, Jon Guymon, James Healy, Evan David Light, Chris Lloyd, Adam Meehan, Kyle Neath, Lawrence Pit, T.J. Sheehy, Roland Swingler, Gareth Townsend, Matt Wastrodowski, Ian White

Thanks to Thoughtbot's Factory Girl. Machinist was written because I loved the idea behind Factory Girl, but I thought the philosophy wasn't quite right, and I hated the syntax.

Jump to Line
Something went wrong with that request. Please try again.