Created
September 15, 2022 17:30
-
-
Save rubendinho/1c75d4cd3a0f6668738f90d1e9224bb5 to your computer and use it in GitHub Desktop.
Testing your FactoryBot factories and defined traits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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