Skip to content

Instantly share code, notes, and snippets.

@rubendinho
Created September 15, 2022 17:30
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 rubendinho/1c75d4cd3a0f6668738f90d1e9224bb5 to your computer and use it in GitHub Desktop.
Save rubendinho/1c75d4cd3a0f6668738f90d1e9224bb5 to your computer and use it in GitHub Desktop.
Testing your FactoryBot factories and defined traits
require 'rails_helper'
RSpec.describe 'Factories', :vcr do
FactoryBot.factories.each do |factory|
describe "The :#{factory.name} factory" do
describe 'base factory' do
it 'is valid' do
expect(build(factory.name.to_sym)).to be_valid
end
end
factory.defined_traits.each do |trait|
context "with :#{trait.name} trait" do
it 'is valid' do
expect(build(factory.name.to_sym, trait.name.to_sym)).to be_valid
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment