Skip to content

Instantly share code, notes, and snippets.

@mattscilipoti
Created January 3, 2011 19:53
Show Gist options
  • Select an option

  • Save mattscilipoti/763858 to your computer and use it in GitHub Desktop.

Select an option

Save mattscilipoti/763858 to your computer and use it in GitHub Desktop.
Ensures all factories are valid (with exceptions)
require 'spec_helper'
describe Factory do
# convention: "base" factories return valid models.
# without these tests, factories with invalid associations are difficult to identify and debug
# Note: performs build, not create.
describe 'all factories,' do
factories_to_skip = {}
factories_to_skip[:user_session] = "You must activate the Authlogic::Session::Base.controller with a controller object before creating objects"
#tried:
# http://rails.anyware-technologies.com.br/2009/04/21/tdd-on-rails-4-rspec-authlogic-factory_girl-and-resource_controller/
# http://iain.nl/2008/11/authlogic-is-awesome/
# http://groups.google.com/group/authlogic/browse_thread/thread/ebfb695082c7663e
factory_names = Factory.factories.keys.map(&:to_s).sort
factory_names.each do |factory_name|
it 'should be valid' do
should_skip = factories_to_skip[factory_name.to_sym]
if should_skip
pending "PENDING: skipping Factory(:#{factory_name}), due to '#{should_skip}'"
else
@it = Factory.build(factory_name)
@it.should be_valid, @it.errors.full_messages
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment