Skip to content

Refactor `namespace_projects_resolver_spec.rb` to use less `let`

What does this MR do and why?

While working on !142396 (merged), a bot mentioned that the namespace_projects_resolver_spec.rb makes heavy use of let for groups and projects.

I have refactored the spec to make use of let_it_be

Why 2 less examples

Two of my changes resulted in 2 less examples because they were exercising the same code and covered by other examples.

  1. it 'finds all projects not aimed for deletion' and it 'finds all projects not aimed for deletion including the subgroups' was collapsed into 1 example
  2. The original context 'with an user namespace'.it 'finds all projects' and context 'with an user namespace'.it 'finds all projects including the subgroups' were actually the same example and not actually testing distinct situations. I collapsed them into a single example

Stats

Summary

When running the spec locally with bundle exec rspec spec/graphql/resolvers/namespace_projects_resolver_spec.rb I see the following timing differences in the output:

  • before: Finished in 26.14 seconds (files took 11.58 seconds to load)
  • after: Finished in 6.63 seconds (files took 11.43 seconds to load)

Before

~/gitlab-development-kit/gitlab$ RD_PROF=1 bundle exec rspec spec/graphql/resolvers/namespace_projects_resolver_spec.rb
[TEST PROF INFO] RSpecDissect enabled

Test environment set up in 0.926308698 seconds
...............
[TEST PROF INFO] RSpecDissect report

Total time: 00:23.597

Total `let` time: 00:17.428
Total `before(:each)` time: 00:23.036


Finished in 26.92 seconds (files took 11.62 seconds to load)
15 examples, 0 failures

[TEST PROF INFO] Time spent in factories: 00:17.444 (61.5% of total time)

After

~/gitlab-development-kit/gitlab$ RD_PROF=1 bundle exec rspec spec/graphql/resolvers/namespace_projects_resolver_spec.rb
[TEST PROF INFO] RSpecDissect enabled

Test environment set up in 0.878414488 seconds
.............
[TEST PROF INFO] RSpecDissect report

Total time: 00:01.030

Total `let` time: 00:00.420
Total `before(:each)` time: 00:00.475


Finished in 6.63 seconds (files took 11.43 seconds to load)
13 examples, 0 failures

[TEST PROF INFO] Time spent in factories: 00:02.126 (26.4% of total time)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #438946 (closed)

Edited by Michael Becker

Merge request reports