Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rails plugin that generates factory_girl Factories for all ActiveRecord models
Branch: master
Pull request Compare This branch is 16 commits ahead, 1 commit behind mdarby:master.
Failed to load latest commit information.
lib I present Sweatshop
tasks
test
MIT-LICENSE
README.textile
Rakefile
init.rb
install.rb
uninstall.rb

README.textile

Sweatshop

A Rails plugin that generates factory_girl Factories AND machinist Blueprints for all of your ActiveRecord models. This fork (mileszs) will place all factories in one file (test/factories.rb or spec/factories.rb for factory_girl) or (test/blueprints.rb or spec/blueprints.rb for machinist). It will also generate an association line (like ‘o.user { |a| a.association(:user) }’ for factory_girl) or ( ‘user’ for machinist) for fields like ‘something_id’.

Requirements

You should probably have either the factory_girl or machinist gem installed.

How to Install & Use

Factory Girl Instructions

Install the factory_girl gem


gem install thoughtbot-factory_girl --source http://gems.github.com

Install the plugin


./script/plugin install git://github.com/mileszs/sweatshop.git

Run the following rake task to generate your Factories


rake sweatshop:generate or rake sweatshop:generate:factories

You can also specify specific models if you do not want to generate all of them.


rake sweatshop:generate MODELS="User Post Comment"

Make sure you put the two following lines into test/test_helper or spec/spec_helper.rb, as the task advises:


  require 'factory_girl'
  require File.expand_path(File.dirname(__FILE__)) + '/factories'

Machinist Instructions

This plugin is slightly less useful for the machinist plugin given that machinist already dynamically sets defaults for your models. You would generally override these defaults only for specific attributes that you are testing. However, for large tables it can be handy to see all of the columns and quickly cut out anything that is not necessary.

Install the machinist gem


gem install notahat-machinist --source http://gems.github.com

Install the plugin


./script/plugin install git://github.com/mileszs/sweatshop.git

Run the following rake task to generate your Factories


rake sweatshop:generate:blueprints

You can also specify specific models if you do not want to generate all of them.


rake sweatshop:generate:blueprints MODELS="User Post Comment"

Make sure you put the following line in test/test_helper or spec/spec_helper.rb, as the task advises:


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

Also, set Sham to reset before each test. In the class Test::Unit::TestCase block in your test_helper.rb, add:

  setup { Sham.reset }

or, if you’re on RSpec, in the Spec::Runner.configure block in your spec_helper.rb, add:

  config.before(:each) { Sham.reset }

Notes

In this fork of sweatshop (mileszs), all factories are placed in test/factories.rb (or spec/factories.rb). Having separate files per model is too much like fixtures for my tastes — I want to see all of my factories in one file. If you would prefer separate files, as of now (1-16-09) the original sweatshop retains the multiple-files method: mdarby-sweatshop .

About the Author

My name is Matt Darby. I’m a 29 year old professional Web Developer and IT Manager. I am the IT Manager and Lead Web Developer at Dynamix Engineering and recently earned a Master’s Degree in Computer Science from Franklin University in Columbus, OH.

Feel free to check out my blog or to recommend me

Something went wrong with that request. Please try again.