Optimize factory usage for runner entity spec
What does this MR do and why?
This MR replaces create with build_stubbed in spec/serializers/runner_entity_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/serializers/runner_entity_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 2.235s (10.87% of total time)
After optimization:
- Factory time: 0.090s (0.54% of total time)
- Factory time reduced by: 2.145s
- Factory time percentage reduced by: 10.33%
- Overall factory usage improvement: 95.97%
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.3433340000046883 seconds
....[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 4
Total wasted time: 00:02.207
RunnerEntity (./spec/serializers/runner_entity_spec.rb:5) (16 records created, 00:02.207)
contains required fields (./spec/serializers/runner_entity_spec.rb:20) – 4 records created, 00:01.532
contains edit_path field (./spec/serializers/runner_entity_spec.rb:26) – 4 records created, 00:00.235
does not contain admin_path field (./spec/serializers/runner_entity_spec.rb:31) – 4 records created, 00:00.221
contains admin_path field (./spec/serializers/runner_entity_spec.rb:39) – 4 records created, 00:00.217
Finished in 15.38 seconds (files took 15.62 seconds to load)
4 examples, 0 failures
[TEST PROF INFO] Time spent in factories: 00:02.246 (11.2% of total time)
Factory time before the update
[TEST PROF INFO] Time spent in factories: 00:02.235 (10.87% of total time)Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.090 (0.54% 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.