RSpec: Enable zero monkey patching before loading more RSpec code
What does this MR do and why?
This MR enables Zero monkey patching mode for RSpec before loading any other RSpec code like shared examples/contexts.
It also fixes the remaining instances where bare shared_examples
used.
This MR also enabled zero monkey patching mode for fast specs
Came up while working on https://gitlab.com/gitlab-org/security/gitlab/-/merge_requests/2681/diffs#note_1065843571.
Refs #220018 (comment 1065725306).
How to set up and validate locally
# Run any normal spec
bin/rspec --dry-run spec/models/project_spec.rb
# Run any fast spec
bin/rspec --dry-run spec/rubocop/todo_dir_spec.rb
# Run any QA spec
cd qa/
bundle exec rspec --dry-run qa/specs/features/api/1_manage/rate_limits_spec.rb
Before
# Revert a single fix from this MR
git checkout master -- ee/spec/support/shared_examples/models/requirement_issues_examples.rb
$ bin/rspec --dry-run spec/models/project_spec.rb
warning: parser/current is loading parser/ruby27, which recognizes2.7.6-compliant syntax, but you are running 2.7.5.
Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
An error occurred while loading ./spec/models/project_spec.rb.
Failure/Error: require_relative('../ee/spec/spec_helper') if Gitlab.ee?
NoMethodError:
undefined method `shared_examples' for main:Object
# ./ee/spec/support/shared_examples/models/requirement_issues_examples.rb:3:in `<main>'
# ./ee/spec/spec_helper.rb:8:in `block in <main>'
# ./ee/spec/spec_helper.rb:8:in `each'
# ./ee/spec/spec_helper.rb:8:in `<main>'
# ./spec/spec_helper.rb:59:in `require_relative'
# ./spec/spec_helper.rb:59:in `<top (required)>'
# ./spec/models/project_spec.rb:3:in `require'
# ./spec/models/project_spec.rb:3:in `<top (required)>'
No examples found.
Finished in 0.00005 seconds (files took 5.93 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Peter Leitzen