ywen / machinist

Fixtures aren't fun. Machinist is.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

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

About

Fixtures aren't fun. Machinist is.

License:MIT License


Languages

Language:Ruby 100.0%