Skip to content

Testing all Factories (with RSpec)

3den edited this page Jan 13, 2012 · 27 revisions

To make sure that you models are valid you can automatically test all your factories with the following code:

require 'spec_helper'

describe Factory do
  FactoryGirl.factories.each do |factory|
    context "with factory for :#{factory.name}" do
      subject {Factory.build(factory.name)}

      it "is valid" do
        subject.valid?.should be, subject.errors.full_messages
      end
    end
  end
end