Testing Factories
We noticed that every once in a while our factories would fail to build. And naturally that would cause most of our tests to fail.
So this little test will ensure that all factories are valid and we run this before any other spec.
spec/factories/factories_spec.rb
require 'spec_helper'
describe "Factory" do
FactoryGirl.factories.map(&:name).each do |factory_name|
context "#{factory_name}" do
subject { Factory.create(factory_name) }
it {
subject.persisted?.should be_true
subject.errors.should be_empty
subject.valid?.should be_true
}
end
end
end
Written by Dmitriy Likhten
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#