Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 44,763
    • Issues 44,763
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,330
    • Merge requests 1,330
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #340487
Closed
Open
Issue created Sep 09, 2021 by Peter Leitzen@splattael🔴Maintainer1 of 4 checklist items completed1/4 checklist items

Disallow stubbing in factories

Problem

Stubbing in factories doesn't play well with let_it_be and lead to errors like:

 Failure/Error: allow(merge_request).to receive(:fetch_ref!)
       The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported.

See #247111 and https://gitlab.com/gitlab-org/gitlab/-/blob/00a771a3cfc095c6904b6b13f59f3435762175ae/spec/factories/merge_requests.rb#L319-324.

let_it_be helps us to improve our test efficiency. See plan#145 (closed).

Current use

Likely, stubbing in factories is only used rarely as of today:

  • spec/factories/deployments.rb
  • spec/factories/commits.rb
  • spec/factories/projects.rb
  • spec/factories/container_repositories.rb
  • spec/factories/merge_requests.rb
  • spec/factories/clusters/applications/helm.rb
  • spec/factories/ci/builds.rb

Proposed solution

  • Document that allow is discouraged in factories - !69965 (merged)
  • Suggest alternatives to stubbing in factories
  • Create a 👮 RuboCop rule to ban the use of allow and expect in factories
  • Remove remaining offenses
Assignee
Assign to
Time tracking