Skip to content

Instantly share code, notes, and snippets.

@skycocker
Created June 6, 2021 15:35
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 skycocker/24ad32c63e9dad2eb7bdfd30e8c7a2e8 to your computer and use it in GitHub Desktop.
Save skycocker/24ad32c63e9dad2eb7bdfd30e8c7a2e8 to your computer and use it in GitHub Desktop.
A simple rspec factory validator
require 'rails_helper'
FactoryBot.factories.each do |factory|
describe "The #{factory.name} factory" do
it 'is valid' do
expect(build(factory.name)).to be_valid
end
describe 'traits' do
factory.defined_traits.each do |trait|
it trait.name do
expect(build(factory.name, trait.name)).to be_valid
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment