Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
632434f9
Commit
632434f9
authored
Oct 10, 2020
by
Peter Leitzen
Committed by
Igor Drozdov
Oct 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed up factories spec by using FactoryDefault
parent
e0e5ab3c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
1 deletion
+29
-1
spec/factories_spec.rb
spec/factories_spec.rb
+29
-1
No files found.
spec/factories_spec.rb
View file @
632434f9
...
...
@@ -3,7 +3,7 @@
require
'spec_helper'
RSpec
.
describe
'factories'
do
FactoryBot
.
factories
.
each
do
|
factory
|
shared_examples
'factory'
do
|
factory
|
describe
"
#{
factory
.
name
}
factory"
do
it
'does not raise error when built'
do
expect
{
build
(
factory
.
name
)
}.
not_to
raise_error
...
...
@@ -22,4 +22,32 @@ RSpec.describe 'factories' do
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment