2019-10-06 23:07:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-08-28 01:42:28 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe 'factories' do
|
2020-10-09 23:08:52 -04:00
|
|
|
shared_examples 'factory' do |factory|
|
2016-03-29 07:39:27 -04:00
|
|
|
describe "#{factory.name} factory" do
|
2017-05-31 09:43:19 -04:00
|
|
|
it 'does not raise error when built' do
|
|
|
|
expect { build(factory.name) }.not_to raise_error
|
|
|
|
end
|
2016-03-29 07:39:27 -04:00
|
|
|
|
2016-05-23 14:16:35 -04:00
|
|
|
it 'does not raise error when created' do
|
2017-05-31 09:43:19 -04:00
|
|
|
expect { create(factory.name) }.not_to raise_error
|
2016-03-29 07:39:27 -04:00
|
|
|
end
|
|
|
|
|
2017-05-31 09:43:19 -04:00
|
|
|
factory.definition.defined_traits.map(&:name).each do |trait_name|
|
|
|
|
describe "linting #{trait_name} trait" do
|
|
|
|
skip 'does not raise error when created' do
|
|
|
|
expect { create(factory.name, trait_name) }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2016-03-29 07:39:27 -04:00
|
|
|
end
|
2012-08-28 01:42:28 -04:00
|
|
|
end
|
|
|
|
end
|
2020-10-09 23:08:52 -04:00
|
|
|
|
|
|
|
# FactoryDefault speed up specs by creating associations only once
|
|
|
|
# and reuse them in other factories.
|
|
|
|
#
|
|
|
|
# However, for some factories we cannot use FactoryDefault because the
|
|
|
|
# associations must be unique and cannot be reused.
|
|
|
|
skip_factory_defaults = %i[
|
|
|
|
fork_network_member
|
|
|
|
].to_set.freeze
|
|
|
|
|
|
|
|
without_fd, with_fd = FactoryBot.factories
|
|
|
|
.partition { |factory| skip_factory_defaults.include?(factory.name) }
|
|
|
|
|
|
|
|
context 'with factory defaults', factory_default: :keep do
|
|
|
|
let_it_be(:namespace) { create_default(:namespace) }
|
|
|
|
let_it_be(:project) { create_default(:project, :repository) }
|
|
|
|
let_it_be(:user) { create_default(:user) }
|
|
|
|
|
|
|
|
with_fd.each do |factory|
|
|
|
|
it_behaves_like 'factory', factory
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without factory defaults' do
|
|
|
|
without_fd.each do |factory|
|
|
|
|
it_behaves_like 'factory', factory
|
|
|
|
end
|
|
|
|
end
|
2012-08-28 01:42:28 -04:00
|
|
|
end
|