Skip to content

Instantly share code, notes, and snippets.

@alxndr
Last active November 24, 2015 20:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save alxndr/4053301 to your computer and use it in GitHub Desktop.
test FactoryGirl factories (including uniqueness)
require 'spec_helper'
non_idempotent_factories = [:the_president] # singletons
broken_factories = [] # just in case
FactoryGirl.factories.map(&:name).reject{|factory_sym| broken_factories.include? factory_sym}.each do |factory_sym|
factory_name = factory_sym.to_s.camelize
describe "The #{factory_name} factory" do
let(:first) { FactoryGirl.build factory_sym }
it 'should be valid' do
expect(first).to be_valid?, first.errors.full_messages.to_sentence
end
describe "creating a second #{factory_name}" do
before do
first.save
end
it 'should be valid' do
second = FactoryGirl.build(factory_sym)
expect(second).to be_valid?, second.errors.full_messages.to_sentence
end
end unless non_idempotent_factories.include? factory_sym
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment