1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/spec/acceptance/lint_spec.rb
Joshua Clayton 6a692fe711 Add FactoryGirl.lint to ensure all factories are valid
This commit adds FactoryGirl.lint, which iterates over each defined
factory, builds it, and ensures it is valid. If any factories are
invalid, an exception is raised and includes the names of each invalid
factory.
2014-02-07 22:21:08 -05:00

55 lines
1.1 KiB
Ruby

require 'spec_helper'
describe 'FactoryGirl.lint' do
it 'raises when a factory is invalid' do
define_model 'User', name: :string do
validates :name, presence: true
end
define_model 'AlwaysValid'
FactoryGirl.define do
factory :user do
factory :admin_user
end
factory :always_valid
end
error_message = <<-ERROR_MESSAGE.strip
The following factories are invalid:
* user
* admin_user
ERROR_MESSAGE
expect do
FactoryGirl.lint
end.to raise_error FactoryGirl::InvalidFactoryError, error_message
end
it 'does not raise when all factories are valid' do
define_model 'User', name: :string do
validates :name, presence: true
end
FactoryGirl.define do
factory :user do
name 'assigned'
end
end
expect { FactoryGirl.lint }.not_to raise_error
end
it 'supports models which do not respond to #valid?' do
define_class 'Thing'
FactoryGirl.define do
factory :thing
end
expect(Thing.new).not_to respond_to(:valid?)
expect { FactoryGirl.lint }.not_to raise_error
end
end