diff options
author | Rémy Coutable <remy@rymai.me> | 2019-04-18 22:08:04 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-05-20 14:31:58 +0200 |
commit | 4d9c76e9e44119ee2578c94b2b98bb72e80e874b (patch) | |
tree | 441a0b95536a35959f237c487cfba44f5dbdd7ed /spec | |
parent | 27d207bd8fa0ca095f4008fbcc62c0b924b8c405 (diff) | |
download | gitlab-ce-4d9c76e9e44119ee2578c94b2b98bb72e80e874b.tar.gz |
Reorganize test jobs by levelreorganize-tests-jobs-by-level
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/quality/test_level_spec.rb | 105 | ||||
-rw-r--r-- | spec/spec_helper.rb | 5 | ||||
-rw-r--r-- | spec/support/shared_examples/finders/assignees_filter_shared_examples.rb (renamed from spec/support/shared_examples/finders/assignees_filter_spec.rb) | 0 | ||||
-rw-r--r-- | spec/support/shared_examples/models/atomic_internal_id_shared_examples.rb (renamed from spec/support/shared_examples/models/atomic_internal_id_spec.rb) | 0 | ||||
-rw-r--r-- | spec/support/shared_examples/models/chat_service_shared_examples.rb (renamed from spec/support/shared_examples/models/chat_service_spec.rb) | 0 | ||||
-rw-r--r-- | spec/support/shared_examples/models/update_project_statistics_shared_examples.rb (renamed from spec/support/shared_examples/models/update_project_statistics_spec.rb) | 0 | ||||
-rw-r--r-- | spec/support/shared_examples/requests/api/issues_shared_examples.rb (renamed from spec/support/shared_examples/requests/api/issues_shared_example_spec.rb) | 0 |
7 files changed, 109 insertions, 1 deletions
diff --git a/spec/lib/quality/test_level_spec.rb b/spec/lib/quality/test_level_spec.rb new file mode 100644 index 00000000000..3465c3a050b --- /dev/null +++ b/spec/lib/quality/test_level_spec.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +RSpec.describe Quality::TestLevel do + describe '#pattern' do + context 'when level is unit' do + it 'returns a pattern' do + expect(subject.pattern(:unit)) + .to eq("spec/{bin,config,db,dependencies,factories,finders,frontend,graphql,helpers,initializers,javascripts,lib,migrations,models,policies,presenters,rack_servers,routing,rubocop,serializers,services,sidekiq,tasks,uploaders,validators,views,workers,elastic_integration}{,/**/}*_spec.rb") + end + end + + context 'when level is integration' do + it 'returns a pattern' do + expect(subject.pattern(:integration)) + .to eq("spec/{controllers,mailers,requests}{,/**/}*_spec.rb") + end + end + + context 'when level is system' do + it 'returns a pattern' do + expect(subject.pattern(:system)) + .to eq("spec/{features}{,/**/}*_spec.rb") + end + end + + context 'with a prefix' do + it 'returns a pattern' do + expect(described_class.new('ee/').pattern(:system)) + .to eq("ee/spec/{features}{,/**/}*_spec.rb") + end + end + + describe 'performance' do + it 'memoizes the pattern for a given level' do + expect(subject.pattern(:system).object_id).to eq(subject.pattern(:system).object_id) + end + + it 'freezes the pattern for a given level' do + expect(subject.pattern(:system)).to be_frozen + end + end + end + + describe '#regexp' do + context 'when level is unit' do + it 'returns a regexp' do + expect(subject.regexp(:unit)) + .to eq(%r{spec/(bin|config|db|dependencies|factories|finders|frontend|graphql|helpers|initializers|javascripts|lib|migrations|models|policies|presenters|rack_servers|routing|rubocop|serializers|services|sidekiq|tasks|uploaders|validators|views|workers|elastic_integration)}) + end + end + + context 'when level is integration' do + it 'returns a regexp' do + expect(subject.regexp(:integration)) + .to eq(%r{spec/(controllers|mailers|requests)}) + end + end + + context 'when level is system' do + it 'returns a regexp' do + expect(subject.regexp(:system)) + .to eq(%r{spec/(features)}) + end + end + + context 'with a prefix' do + it 'returns a regexp' do + expect(described_class.new('ee/').regexp(:system)) + .to eq(%r{ee/spec/(features)}) + end + end + + describe 'performance' do + it 'memoizes the regexp for a given level' do + expect(subject.regexp(:system).object_id).to eq(subject.regexp(:system).object_id) + end + + it 'freezes the regexp for a given level' do + expect(subject.regexp(:system)).to be_frozen + end + end + end + + describe '#level_for' do + it 'returns the correct level for a unit test' do + expect(subject.level_for('spec/models/abuse_report_spec.rb')).to eq(:unit) + end + + it 'returns the correct level for an integration test' do + expect(subject.level_for('spec/mailers/abuse_report_mailer_spec.rb')).to eq(:integration) + end + + it 'returns the correct level for a system test' do + expect(subject.level_for('spec/features/abuse_report_spec.rb')).to eq(:system) + end + + it 'raises an error for an unknown level' do + expect { subject.level_for('spec/unknown/foo_spec.rb') } + .to raise_error(described_class::UnknownTestLevelError, + %r{Test level for spec/unknown/foo_spec.rb couldn't be set. Please rename the file properly or change the test level detection regexes in .+/lib/quality/test_level.rb.}) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 69589c9aa33..390a869d93f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,6 +44,8 @@ Dir[Rails.root.join("spec/support/shared_contexts/*.rb")].each { |f| require f } Dir[Rails.root.join("spec/support/shared_examples/*.rb")].each { |f| require f } Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } +quality_level = Quality::TestLevel.new + RSpec.configure do |config| config.use_transactional_fixtures = false config.use_instantiated_fixtures = false @@ -55,9 +57,10 @@ RSpec.configure do |config| config.infer_spec_type_from_file_location! config.full_backtrace = !!ENV['CI'] - config.define_derived_metadata(file_path: %r{/spec/}) do |metadata| + config.define_derived_metadata(file_path: %r{(ee)?/spec/.+_spec\.rb\z}) do |metadata| location = metadata[:location] + metadata[:level] = quality_level.level_for(location) metadata[:api] = true if location =~ %r{/spec/requests/api/} # do not overwrite type if it's already set diff --git a/spec/support/shared_examples/finders/assignees_filter_spec.rb b/spec/support/shared_examples/finders/assignees_filter_shared_examples.rb index 782a2d97746..782a2d97746 100644 --- a/spec/support/shared_examples/finders/assignees_filter_spec.rb +++ b/spec/support/shared_examples/finders/assignees_filter_shared_examples.rb diff --git a/spec/support/shared_examples/models/atomic_internal_id_spec.rb b/spec/support/shared_examples/models/atomic_internal_id_shared_examples.rb index a248f60d23e..a248f60d23e 100644 --- a/spec/support/shared_examples/models/atomic_internal_id_spec.rb +++ b/spec/support/shared_examples/models/atomic_internal_id_shared_examples.rb diff --git a/spec/support/shared_examples/models/chat_service_spec.rb b/spec/support/shared_examples/models/chat_service_shared_examples.rb index 0a302e7d030..0a302e7d030 100644 --- a/spec/support/shared_examples/models/chat_service_spec.rb +++ b/spec/support/shared_examples/models/chat_service_shared_examples.rb diff --git a/spec/support/shared_examples/models/update_project_statistics_spec.rb b/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb index 7a04e940ee5..7a04e940ee5 100644 --- a/spec/support/shared_examples/models/update_project_statistics_spec.rb +++ b/spec/support/shared_examples/models/update_project_statistics_shared_examples.rb diff --git a/spec/support/shared_examples/requests/api/issues_shared_example_spec.rb b/spec/support/shared_examples/requests/api/issues_shared_examples.rb index 1133e95e44e..1133e95e44e 100644 --- a/spec/support/shared_examples/requests/api/issues_shared_example_spec.rb +++ b/spec/support/shared_examples/requests/api/issues_shared_examples.rb |