Optimize factory usage for dast site profile new
What does this MR do and why?
This MR replaces create with build_stubbed in ee/spec/views/projects/security/dast_site_profiles/new.html.haml_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 ee/spec/views/projects/security/dast_site_profiles/new.html.haml_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 1.677s (8.8% of total time)
After optimization:
- Factory time: 0.215s (1.2% of total time)
- Factory time reduced by: 1.462s
- Factory time percentage reduced by: 7.6%
- Overall factory usage improvement: 87.2%
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
==> Go projects set up in 0.704 seconds...
Test environment set up in 2.4931500000529923 seconds
...[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 3
Total wasted time: 00:01.658
projects/security/dast_site_profiles/new (./ee/spec/views/projects/security/dast_site_profiles/new.html.haml_spec.rb:5) (9 records created, 00:01.658)
renders Vue app root (./ee/spec/views/projects/security/dast_site_profiles/new.html.haml_spec.rb:11) – 3 records created, 00:01.208
passes project's full path (./ee/spec/views/projects/security/dast_site_profiles/new.html.haml_spec.rb:15) – 3 records created, 00:00.218
passes DAST profiles library URL (./ee/spec/views/projects/security/dast_site_profiles/new.html.haml_spec.rb:19) – 3 records created, 00:00.231
Finished in 13.98 seconds (files took 16.43 seconds to load)
3 examples, 0 failures
[TEST PROF INFO] Time spent in factories: 00:01.670 (9.03% of total time)
Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.215 (1.2% of total time)
This MR also adds the missing feature category in this spec.
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.