Skip to content
代码片段 群组 项目
提交 fc560baf 编辑于 作者: Igor Drozdov's avatar Igor Drozdov
浏览文件

Merge branch 'pl-spec-factries-perf' into 'master'

Speed up factories spec by using FactoryDefault

See merge request gitlab-org/gitlab!44561
No related branches found
No related tags found
无相关合并请求
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'factories' do RSpec.describe 'factories' do
FactoryBot.factories.each do |factory| shared_examples 'factory' do |factory|
describe "#{factory.name} factory" do describe "#{factory.name} factory" do
it 'does not raise error when built' do it 'does not raise error when built' do
expect { build(factory.name) }.not_to raise_error expect { build(factory.name) }.not_to raise_error
...@@ -22,4 +22,32 @@ ...@@ -22,4 +22,32 @@
end end
end end
end end
# 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
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册