Jeff Kreeftmeijer

Making Machinist master MongoMapper & Mongoid


A couple of months back, I wrote a minimal install guide for machinist_mongo by @nmerouze and @shingara. Back then it was called machinist_mongomapper, it didn’t support Mongoid yet and the Rails beta hadn’t even been released yet, so I think it’s about time for an update.

You know Machinist, right? Here’s the short explanation:

“Fixtures aren’t fun. Machinist is.

Machinist makes it easy to create test data within your tests. It generates data for the fields you don’t care about, and constructs any necessary associated objects, leaving you to only specify the fields you do care about in your tests.”

I’m not going to go into Machinist itself here, so be sure to read the README.

On to installing machinist_mongo. Put this in your Gemfile:

gem 'machinist_mongo'

And run:

$ bundle install

Or — if you’re using Rails 2.x — put this in config/environment.rb:

config.gem 'machinist_mongo'

And run:

$ rake gems:install

Now create your spec/blueprints.rb or test/blueprints.rb file as you normally would, only using Mongoid or MongoMapper instead of ActiveRecord:

require 'machinist/mongo_mapper' # or mongoid
require 'sham'

Don’t forget to require the new blueprints.rb file in your spec_helper (or test_helper):

require File.expand_path(File.dirname(__FILE__) + "/blueprints")

And you’re all set. Again, be sure read Machinist’s README to find out how to create your objects and get this thing running.

machinist_mongo aims to support all mongoDB ORMs, so If you’re using something other than MongoMapper or Mongoid, please be sure to write a adapter for it. Also, can anyone tell me why this isn’t merged into Machinist itself? Because I think it should.