Enable running simplecov in fast specs via `SIMPLECOV=1`

What does this MR do and why?

This MR adds simplecov functionality to "fast specs" (specs which require 'spec/fast_spec_helper') so we can see test coverage for them as well. See https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#coverage.

It also tweaks a RuboCop spec to use require 'spec/fast_spec_helper' so the command below does not fail with:

Detected fast_spec_helper is loaded first than spec_helper.
If running test files using both spec_helper and fast_spec_helper,
make sure test file with spec_helper is loaded first.
Aborting...
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

But why now?

Now, with https://docs.gitlab.com/ee/development/pipelines.html#undercover-rspec-test we encourage developers to have a code coverage of 100%. undercover wasn't available at time of writing some of the cops.

How to set up and validate locally

With simplecov enabled

$ SIMPLECOV=1 bin/rspec -f p $(find spec/rubocop -name "*_spec.rb")
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 29880
.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Finished in 1.49 seconds (files took 2.5 seconds to load)
1031 examples, 0 failures

Randomized with seed 29880

Coverage report generated for RSpec to /home/peter/devel/gitlab/gdk-ee/gitlab/coverage. 2573 / 334560 LOC (0.77%) covered.

Coverage report generated for RSpec to /home/peter/devel/gitlab/gdk-ee/gitlab/coverage/coverage.xml
Lcov style coverage report generated for RSpec to /home/peter/devel/gitlab/gdk-ee/gitlab/coverage/lcov/gitlab.lcov

With simplecov disabled

$ bin/rspec -f p $(find spec/rubocop -name "*_spec.rb")
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 7399
.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Finished in 2.32 seconds (files took 2.35 seconds to load)
1031 examples, 0 failures

Randomized with seed 7399

Follow up

It seems we are missing specs for some 👮 rules:

Line coverage for rubocop/*
Screenshot_from_2022-03-09_14-39-34

See #355012

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports

Loading