Skip to content

Flag when we create too many items in RSpec Factories

Problem

Some tests are very slow because they create a lot of DB records via factories (e.g. !122198 (merged)). See a list of the current offenders.

create_list(:merge_request, 1001, :unique_branches, source_project: project, author: user, state: :opened)

This line above will create 1001 merge requests for a single test. This is highly inefficient, and there are more performant ways to have the same results.

Proposed solution

Write a cop RSpec/FactoryBot/ExcessiveCreateList with a MaxAmount argument:

# bad (we assume `MaxAmount: 10`)
create_list(:merge_request, 1001, state: :opened)

# good (we assume `MaxAmount: 10`)
create_list(:merge_request, 9, state: :opened)

Real world example

Edited by David Dieulivol