-
Notifications
You must be signed in to change notification settings - Fork 134
Getting Started
(These installation instructions are for Rails 3. For other installation options, see the Installation page.)
In your app’s Gemfile
, in the group :test
section, add:
gem 'machinist', '>= 2.0.0.beta1'
Then run:
bundle install
rails generate machinist:install
Learn more about Installation
A blueprint tells Machinist how to generate an object. The blueprint takes care of making up values for the attributes that you don’t care about in your test, leaving you to focus on the just the things that you’re testing.
Post.blueprint do
title { "A Post" }
body { "Lorem ipsum..." }
end
Blueprints live in your test/blueprints.rb
(or spec/support/blueprints.rb
) file.
Learn more about Blueprints
Once you’ve defined a blueprint for a class, you can construct an object of that class with:
Post.make
To override attributes in the blueprint, pass them in as a hash:
Post.make(:title => "Special Title")
To save the object to the database, use make!
:
Post.make!
Learn more about Make