Commit 63ae977c authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'force-eager_load-for-specs-require-it' into 'master'

Force eager loading of the application code for specs require it

See merge request gitlab-org/gitlab!73154
parents 2a01cce5 52c9045b
......@@ -64,6 +64,9 @@ use the `GITLAB_TEST_EAGER_LOAD` environment variable:
GITLAB_TEST_EAGER_LOAD=1 bin/rspec spec/models/project_spec.rb
```
If your test depends on all the application code that is being loaded, add the `:eager_load` tag.
This ensures that the application code is eagerly loaded before the test execution.
### Ruby warnings
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47767) in GitLab 13.7.
......
......@@ -192,7 +192,7 @@ RSpec.describe Note, :elastic, :clean_gitlab_redis_shared_state do
note.update!(note: 'some other text here')
end
it 'uses same index for Note subclasses' do
it 'uses same index for Note subclasses', :eager_load do
Note.subclasses.each do |note_class|
expect(note_class.index_name).to eq(Note.index_name)
expect(note_class.document_type).to eq(Note.document_type)
......
......@@ -63,7 +63,7 @@ RSpec.describe Snippet, :elastic do
expect(snippet.__elasticsearch__.as_indexed_json).to eq(expected_hash)
end
it 'uses same index for Snippet subclasses' do
it 'uses same index for Snippet subclasses', :eager_load do
Snippet.subclasses.each do |snippet_class|
expect(snippet_class.index_name).to eq(Snippet.index_name)
expect(snippet_class.document_type).to eq(Snippet.document_type)
......
......@@ -210,7 +210,7 @@ RSpec.describe 'Database schema' do
# We are skipping GEO models for now as it adds up complexity
describe 'for jsonb columns' do
it 'uses json schema validator' do
it 'uses json schema validator', :eager_load do
columns_name_with_jsonb.each do |hash|
next if models_by_table_name[hash["table_name"]].nil?
......
......@@ -32,7 +32,7 @@ RSpec.describe Banzai::Pipeline::PlainMarkdownPipeline do
expect(result[:escaped_literals]).to be_truthy
end
it 'ensure we handle all the GitLab reference characters' do
it 'ensure we handle all the GitLab reference characters', :eager_load do
reference_chars = ObjectSpace.each_object(Class).map do |klass|
next unless klass.included_modules.include?(Referable)
next unless klass.respond_to?(:reference_prefix)
......
......@@ -375,7 +375,7 @@ RSpec.describe ReactiveCaching, :use_clean_rails_memory_store_caching do
end
describe 'classes including this concern' do
it 'sets reactive_cache_work_type' do
it 'sets reactive_cache_work_type', :eager_load do
classes = ObjectSpace.each_object(Class).select do |klass|
klass < described_class && klass.name
end
......
......@@ -8,7 +8,7 @@ RSpec.describe MergeRequests::Mergeability::RunChecksService do
let_it_be(:merge_request) { create(:merge_request) }
describe '#CHECKS' do
it 'contains every subclass of the base checks service' do
it 'contains every subclass of the base checks service', :eager_load do
expect(described_class::CHECKS).to contain_exactly(*MergeRequests::Mergeability::CheckBaseService.subclasses)
end
end
......@@ -19,7 +19,7 @@ RSpec.describe MergeRequests::Mergeability::RunChecksService do
let(:params) { {} }
let(:success_result) { Gitlab::MergeRequests::Mergeability::CheckResult.success }
context 'when every check is skipped' do
context 'when every check is skipped', :eager_load do
before do
MergeRequests::Mergeability::CheckBaseService.subclasses.each do |subclass|
expect_next_instance_of(subclass) do |service|
......
......@@ -431,6 +431,10 @@ RSpec.configure do |config|
Gitlab::Metrics.reset_registry!
end
config.before(:example, :eager_load) do
Rails.application.eager_load!
end
# This makes sure the `ApplicationController#can?` method is stubbed with the
# original implementation for all view specs.
config.before(:each, type: :view) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment