Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fixtures aren't fun. Machinist is.

tree: 870ad0fa3c

Fetching latest commit…

Cannot retrieve the latest commit at this time


Machinist 2

Fixtures aren't fun. Machinist is.

Machinist 2 is still in beta! Unless you really know what you're doing, you probably want Machinist 1.


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, Ben Hoskings, Evan David Light, Chris Lloyd, Adam Meehan, Kyle Neath, Lawrence Pit, Xavier Shay, 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.

Something went wrong with that request. Please try again.