Optimize factory usage for notify helper
What does this MR do and why?
This MR replaces create with build_stubbed in spec/helpers/notify_helper_spec.rb to optimize the factory usage as recommended in our handbook.
This spec is part of the list .rubocop_todo/rspec/factory_bot/avoid_create.yml.
It was verified that database persistence is not needed using the factory doctor command FDOC=1 bin/rspec spec/helpers/notify_helper_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 4.07s (19.74% of total time)
After optimization:
- Factory time: 0.108s (0.65% of total time)
- Factory time reduced by: 3.962s
- Factory time percentage reduced by: 19.09%
- Overall factory usage improvement: 97.3%
Factory Doctor Output
[TEST PROF INFO] FactoryDoctor enabled (event: "sql.active_record", threshold: 0.01)
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
==> Using precompiled Gitaly binaries from cache
Test environment set up in 1.1781020000053104 seconds
...........[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 3
Total wasted time: 00:03.659
NotifyHelper (./spec/helpers/notify_helper_spec.rb:5) (15 records created, 00:03.659)
returns link to merge request with the text reference (./spec/helpers/notify_helper_spec.rb:12) – 4 records created, 00:01.914
returns link to issue with the text reference (./spec/helpers/notify_helper_spec.rb:23) – 5 records created, 00:00.553
returns MR approved description (./spec/helpers/notify_helper_spec.rb:39) – 6 records created, 00:01.191
Finished in 15.99 seconds (files took 13.73 seconds to load)
11 examples, 0 failures
[TEST PROF INFO] Time spent in factories: 00:03.709 (18.66% of total time)
Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.108 (0.65% of total time)References
Relates to: #378910.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.