Skip to content

Testing all Factories (with RSpec)

joshuaclayton edited this page Mar 23, 2012 · 2 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 { FactoryGirl.build(factory.name) }

      it "is valid" do
        subject.valid?.should be, subject.errors.full_messages
      end
    end
  end
end
Clone this wiki locally