Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fixtures aren't fun. Machinist is.

tree: d495e00987

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.markdown

Machinist 2

Fixtures aren't fun. Machinist is.

Introduction

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)
  end
end

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.
end

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

Comment.blueprint do
  post
  email { "commenter-#{sn}@example.com" }
  body  { "Lorem ipsum..." }
end

Check out the documentation for more info.

Contributors

Machinist is maintained by Pete Yandell (pete@notahat.com, @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.

Something went wrong with that request. Please try again.