Skip to content

Instantly share code, notes, and snippets.

@mattscilipoti
Last active May 13, 2016 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattscilipoti/0aa5e4d2895591cd9d5de856418a160f to your computer and use it in GitHub Desktop.
Save mattscilipoti/0aa5e4d2895591cd9d5de856418a160f to your computer and use it in GitHub Desktop.
require 'spec_helper'
RSpec.describe FactoryGirl 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 = {}
FactoryGirl.factories.each do |factory|
it 'should be valid' do
reason_to_skip = factories_to_skip[factory.name.to_sym]
if reason_to_skip
pending "PENDING: skipping Factory(:#{factory_name}), due to '#{reason_to_skip}'"
else
resource = factory.run(:build, {})
# Note: attempted to use be_valid, but errors.full_messages was empty
expect(resource.valid?).to be(true), resource.errors.full_messages.to_s
end
end
end
end
end
@mattscilipoti
Copy link
Author

Updated for rspec 3.4.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment