Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 19:05:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 19:05:49 +0300
commit43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch)
treedceebdc68925362117480a5d672bcff122fb625b /spec/rubocop
parent20c84b99005abd1c82101dfeff264ac50d2df211 (diff)
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/background_migration/feature_category_spec.rb2
-rw-r--r--spec/rubocop/cop/background_migration/missing_dictionary_file_spec.rb137
-rw-r--r--spec/rubocop/cop/gettext/static_identifier_spec.rb174
-rw-r--r--spec/rubocop/cop/gitlab/avoid_feature_get_spec.rb2
-rw-r--r--spec/rubocop/cop/gitlab/deprecate_track_redis_hll_event_spec.rb17
-rw-r--r--spec/rubocop/cop/gitlab/doc_url_spec.rb2
-rw-r--r--spec/rubocop/cop/gitlab/keys_first_and_values_first_spec.rb2
-rw-r--r--spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb15
-rw-r--r--spec/rubocop/cop/gitlab/service_response_spec.rb2
-rw-r--r--spec/rubocop/cop/graphql/authorize_types_spec.rb22
-rw-r--r--spec/rubocop/cop/lint/last_keyword_argument_spec.rb2
-rw-r--r--spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb2
-rw-r--r--spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb2
-rw-r--r--spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb24
-rw-r--r--spec/rubocop/cop/migration/add_reference_spec.rb2
-rw-r--r--spec/rubocop/cop/migration/background_migrations_spec.rb2
-rw-r--r--spec/rubocop/cop/migration/batch_migrations_post_only_spec.rb2
-rw-r--r--spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb8
-rw-r--r--spec/rubocop/cop/migration/schedule_async_spec.rb1
-rw-r--r--spec/rubocop/cop/migration/update_column_in_batches_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/avoid_conditional_statements_spec.rb42
-rw-r--r--spec/rubocop/cop/rspec/avoid_test_prof_spec.rb2
-rw-r--r--spec/rubocop/cop/rspec/httparty_basic_auth_spec.rb (renamed from spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb)2
-rw-r--r--spec/rubocop/cop/rspec/invalid_feature_category_spec.rb14
-rw-r--r--spec/rubocop/cop/rspec/misspelled_aggregate_failures_spec.rb136
-rw-r--r--spec/rubocop/cop/rspec/shared_groups_metadata_spec.rb70
-rw-r--r--spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb48
-rw-r--r--spec/rubocop/cop/search/namespaced_class_spec.rb100
-rw-r--r--spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb123
29 files changed, 787 insertions, 171 deletions
diff --git a/spec/rubocop/cop/background_migration/feature_category_spec.rb b/spec/rubocop/cop/background_migration/feature_category_spec.rb
index 359520b1d9f..1d1b6cfad5a 100644
--- a/spec/rubocop/cop/background_migration/feature_category_spec.rb
+++ b/spec/rubocop/cop/background_migration/feature_category_spec.rb
@@ -4,8 +4,6 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/background_migration/feature_category'
RSpec.describe RuboCop::Cop::BackgroundMigration::FeatureCategory, feature_category: :database do
- let(:cop) { described_class.new }
-
context 'for non background migrations' do
before do
allow(cop).to receive(:in_background_migration?).and_return(false)
diff --git a/spec/rubocop/cop/background_migration/missing_dictionary_file_spec.rb b/spec/rubocop/cop/background_migration/missing_dictionary_file_spec.rb
new file mode 100644
index 00000000000..32b958426b9
--- /dev/null
+++ b/spec/rubocop/cop/background_migration/missing_dictionary_file_spec.rb
@@ -0,0 +1,137 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+require_relative '../../../../rubocop/cop/background_migration/missing_dictionary_file'
+
+RSpec.describe RuboCop::Cop::BackgroundMigration::MissingDictionaryFile, feature_category: :database do
+ let(:config) do
+ RuboCop::Config.new(
+ 'BackgroundMigration/MissingDictionaryFile' => {
+ 'EnforcedSince' => 20230307160251
+ }
+ )
+ end
+
+ context 'for non post migrations' do
+ before do
+ allow(cop).to receive(:in_post_deployment_migration?).and_return(false)
+ end
+
+ it 'does not throw any offense' do
+ expect_no_offenses(<<~RUBY)
+ class QueueMyMigration < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'MyMigration'
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :users,
+ :id
+ )
+ end
+ end
+ RUBY
+ end
+ end
+
+ context 'for post migrations' do
+ before do
+ allow(cop).to receive(:in_post_deployment_migration?).and_return(true)
+ end
+
+ context 'without enqueuing batched migrations' do
+ it 'does not throw any offense' do
+ expect_no_offenses(<<~RUBY)
+ class CreateTestTable < Gitlab::Database::Migration[2.1]
+ def change
+ create_table(:tests)
+ end
+ end
+ RUBY
+ end
+ end
+
+ context 'with enqueuing batched migration' do
+ let(:rails_root) { File.expand_path('../../../..', __dir__) }
+ let(:dictionary_file_path) { File.join(rails_root, 'db/docs/batched_background_migrations/my_migration.yml') }
+
+ context 'for migrations before enforced time' do
+ before do
+ allow(cop).to receive(:version).and_return(20230307160250)
+ end
+
+ it 'does not throw any offenses' do
+ expect_no_offenses(<<~RUBY)
+ class QueueMyMigration < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'MyMigration'
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :users,
+ :id
+ )
+ end
+ end
+ RUBY
+ end
+ end
+
+ context 'for migrations after enforced time' do
+ before do
+ allow(cop).to receive(:version).and_return(20230307160252)
+ end
+
+ it 'throws offense on not having the appropriate dictionary file with migration name as a constant' do
+ expect_offense(<<~RUBY)
+ class QueueMyMigration < Gitlab::Database::Migration[2.1]
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{format("Missing %{file_name}. Use the generator 'batched_background_migration' to create dictionary files automatically. For more details refer: https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#generator", file_name: dictionary_file_path)}
+ MIGRATION = 'MyMigration'
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :users,
+ :id
+ )
+ end
+ end
+ RUBY
+ end
+
+ it 'throws offense on not having the appropriate dictionary file with migration name as a variable' do
+ expect_offense(<<~RUBY)
+ class QueueMyMigration < Gitlab::Database::Migration[2.1]
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{format("Missing %{file_name}. Use the generator 'batched_background_migration' to create dictionary files automatically. For more details refer: https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#generator", file_name: dictionary_file_path)}
+ def up
+ queue_batched_background_migration(
+ 'MyMigration',
+ :users,
+ :id
+ )
+ end
+ end
+ RUBY
+ end
+
+ it 'does not throw offense with appropriate dictionary file' do
+ expect(File).to receive(:exist?).with(dictionary_file_path).and_return(true)
+
+ expect_no_offenses(<<~RUBY)
+ class QueueMyMigration < Gitlab::Database::Migration[2.1]
+ MIGRATION = 'MyMigration'
+
+ def up
+ queue_batched_background_migration(
+ MIGRATION,
+ :users,
+ :id
+ )
+ end
+ end
+ RUBY
+ end
+ end
+ end
+ end
+end
diff --git a/spec/rubocop/cop/gettext/static_identifier_spec.rb b/spec/rubocop/cop/gettext/static_identifier_spec.rb
new file mode 100644
index 00000000000..a0c15d8ad48
--- /dev/null
+++ b/spec/rubocop/cop/gettext/static_identifier_spec.rb
@@ -0,0 +1,174 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+require 'rspec-parameterized'
+
+require_relative '../../../../rubocop/cop/gettext/static_identifier'
+
+RSpec.describe RuboCop::Cop::Gettext::StaticIdentifier, feature_category: :internationalization do
+ describe '#_()' do
+ it 'does not flag correct use' do
+ expect_no_offenses(<<~'RUBY')
+ _('Hello')
+ _('Hello #{name}')
+
+ _('Hello %{name}') % { name: name }
+ format(_('Hello %{name}') % { name: name })
+
+ _('Hello' \
+ 'Multiline')
+ _('Hello' \
+ 'Multiline %{name}') % { name: name }
+
+ var = "Hello"
+ _(var)
+ _(method_name)
+ list.each { |item| _(item) }
+ _(CONST)
+ RUBY
+ end
+
+ it 'flags incorrect use' do
+ expect_offense(<<~'RUBY')
+ _('Hello' + ' concat')
+ ^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `_(...)`.
+ _('Hello'.concat(' concat'))
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `_(...)`.
+ _("Hello #{name}")
+ ^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `_(...)`.
+ _('Hello %{name}' % { name: name })
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `_(...)`.
+ _(format('Hello %{name}') % { name: name })
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `_(...)`.
+ RUBY
+ end
+ end
+
+ describe '#N_()' do
+ it 'does not flag correct use' do
+ expect_no_offenses(<<~'RUBY')
+ N_('Hello')
+ N_('Hello #{name}')
+ N_('Hello %{name}') % { name: name }
+ format(_('Hello %{name}') % { name: name })
+
+ N_('Hello' \
+ 'Multiline')
+
+ var = "Hello"
+ N_(var)
+ N_(method_name)
+ list.each { |item| N_(item) }
+ N_(CONST)
+ RUBY
+ end
+
+ it 'flags incorrect use' do
+ expect_offense(<<~'RUBY')
+ N_('Hello' + ' concat')
+ ^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `N_(...)`.
+ N_("Hello #{name}")
+ ^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `N_(...)`.
+ N_('Hello %{name}' % { name: name })
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `N_(...)`.
+ N_('Hello' \
+ ^^^^^^^^^ Ensure to pass static strings to translation method `N_(...)`.
+ 'Multiline %{name}' % { name: name })
+ N_(format('Hello %{name}') % { name: name })
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `N_(...)`.
+ RUBY
+ end
+ end
+
+ describe '#s_()' do
+ it 'does not flag correct use' do
+ expect_no_offenses(<<~'RUBY')
+ s_('World|Hello')
+ s_('World|Hello #{name}')
+ s_('World|Hello %{name}') % { name: name }
+ format(s_('World|Hello %{name}') % { name: name })
+
+ s_('World|Hello' \
+ 'Multiline')
+
+ var = "Hello"
+ s_(var)
+ s_(method_name)
+ list.each { |item| s_(item) }
+ s_(CONST)
+ RUBY
+ end
+
+ it 'flags incorrect use' do
+ expect_offense(<<~'RUBY')
+ s_("World|Hello #{name}")
+ ^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `s_(...)`.
+ s_('World|Hello' + ' concat')
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `s_(...)`.
+ s_('World|Hello %{name}' % { name: name })
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `s_(...)`.
+ s_('World|Hello' \
+ ^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `s_(...)`.
+ 'Multiline %{name}' % { name: name })
+ s_(format('World|Hello %{name}') % { name: name })
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `s_(...)`.
+ RUBY
+ end
+ end
+
+ describe '#n_()' do
+ it 'does not flag correct use' do
+ expect_no_offenses(<<~'RUBY')
+ n_('Hello', 'Hellos', 2)
+ n_('Hello', 'Hellos', count)
+
+ n_('Hello' ' concat', 'Hellos', 2)
+ n_('Hello', 'Hello' 's', 2)
+
+ n_('Hello %{name}', 'Hellos %{name}', 2) % { name: name }
+ format(n_('Hello %{name}', 'Hellos %{name}', count) % { name: name })
+
+ n_('Hello', 'Hellos' \
+ 'Multiline', 2)
+
+ n_('Hello' \
+ 'Multiline', 'Hellos', 2)
+
+ n_('Hello' \
+ 'Multiline %{name}', 'Hellos %{name}', 2) % { name: name }
+
+ var = "Hello"
+ n_(var, var, 1)
+ n_(method_name, method_name, count)
+ list.each { |item| n_(item, item, 2) }
+ n_(CONST, CONST, 2)
+ RUBY
+ end
+
+ it 'flags incorrect use' do
+ expect_offense(<<~'RUBY')
+ n_('Hello' + ' concat', 'Hellos', 2)
+ ^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `n_(...)`.
+ n_('Hello', 'Hello' + 's', 2)
+ ^^^^^^^^^^^^^ Ensure to pass static strings to translation method `n_(...)`.
+ n_("Hello #{name}", "Hellos", 2)
+ ^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `n_(...)`.
+ n_('Hello %{name}' % { name: name }, 'Hellos', 2)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `n_(...)`.
+ n_('Hello' \
+ ^^^^^^^^^ Ensure to pass static strings to translation method `n_(...)`.
+ 'Multiline %{name}' % { name: name }, 'Hellos %{name}', 2)
+ n_('Hello', format('Hellos %{name}') % { name: name }, count)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Ensure to pass static strings to translation method `n_(...)`.
+ RUBY
+ end
+ end
+
+ describe 'edge cases' do
+ it 'does not flag' do
+ expect_no_offenses(<<~RUBY)
+ n_(s_('World|Hello'), s_('World|Hellos'), 2)
+ RUBY
+ end
+ end
+end
diff --git a/spec/rubocop/cop/gitlab/avoid_feature_get_spec.rb b/spec/rubocop/cop/gitlab/avoid_feature_get_spec.rb
index b5017bebd28..1531042c23a 100644
--- a/spec/rubocop/cop/gitlab/avoid_feature_get_spec.rb
+++ b/spec/rubocop/cop/gitlab/avoid_feature_get_spec.rb
@@ -7,8 +7,6 @@ require_relative '../../../../rubocop/cop/gitlab/avoid_feature_get'
RSpec.describe RuboCop::Cop::Gitlab::AvoidFeatureGet do
let(:msg) { described_class::MSG }
- subject(:cop) { described_class.new }
-
it 'bans use of Feature.ban' do
expect_offense(<<~RUBY)
Feature.get
diff --git a/spec/rubocop/cop/gitlab/deprecate_track_redis_hll_event_spec.rb b/spec/rubocop/cop/gitlab/deprecate_track_redis_hll_event_spec.rb
deleted file mode 100644
index eed30e11a98..00000000000
--- a/spec/rubocop/cop/gitlab/deprecate_track_redis_hll_event_spec.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-require 'rubocop_spec_helper'
-require_relative '../../../../rubocop/cop/gitlab/deprecate_track_redis_hll_event'
-
-RSpec.describe RuboCop::Cop::Gitlab::DeprecateTrackRedisHLLEvent do
- it 'does not flag the use of track_event' do
- expect_no_offenses('track_event :show, name: "p_analytics_insights"')
- end
-
- it 'flags the use of track_redis_hll_event' do
- expect_offense(<<~SOURCE)
- track_redis_hll_event :show, name: 'p_analytics_valuestream'
- ^^^^^^^^^^^^^^^^^^^^^ `track_redis_hll_event` is deprecated[...]
- SOURCE
- end
-end
diff --git a/spec/rubocop/cop/gitlab/doc_url_spec.rb b/spec/rubocop/cop/gitlab/doc_url_spec.rb
index 4a7ef14ccbc..957edc8286b 100644
--- a/spec/rubocop/cop/gitlab/doc_url_spec.rb
+++ b/spec/rubocop/cop/gitlab/doc_url_spec.rb
@@ -3,7 +3,7 @@
require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/gitlab/doc_url'
-RSpec.describe RuboCop::Cop::Gitlab::DocUrl, feature_category: :not_owned do
+RSpec.describe RuboCop::Cop::Gitlab::DocUrl, feature_category: :shared do
context 'when string literal is added with docs url prefix' do
context 'when inlined' do
it 'registers an offense' do
diff --git a/spec/rubocop/cop/gitlab/keys_first_and_values_first_spec.rb b/spec/rubocop/cop/gitlab/keys_first_and_values_first_spec.rb
index 073c78e78c0..b62742d52e2 100644
--- a/spec/rubocop/cop/gitlab/keys_first_and_values_first_spec.rb
+++ b/spec/rubocop/cop/gitlab/keys_first_and_values_first_spec.rb
@@ -7,8 +7,6 @@ require_relative '../../../../rubocop/cop/gitlab/keys_first_and_values_first'
RSpec.describe RuboCop::Cop::Gitlab::KeysFirstAndValuesFirst do
let(:msg) { described_class::MSG }
- subject(:cop) { described_class.new }
-
shared_examples 'inspect use of keys or values first' do |method, autocorrect|
describe ".#{method}.first" do
it 'flags and autocorrects' do
diff --git a/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb b/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb
index bfc0cebe203..96ff01108c3 100644
--- a/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb
+++ b/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb
@@ -201,18 +201,13 @@ RSpec.describe RuboCop::Cop::Gitlab::MarkUsedFeatureFlags do
include_examples 'does not set any flags as used', 'data_consistency :delayed'
end
+ describe 'Class with included WorkerAttributes `data_consistency` method' do
+ include_examples 'sets flag as used', 'ActionMailer::MailDeliveryJob.data_consistency :delayed, feature_flag: :foo', 'foo'
+ include_examples 'does not set any flags as used', 'data_consistency :delayed'
+ end
+
describe 'Worker `deduplicate` method' do
include_examples 'sets flag as used', 'deduplicate :delayed, feature_flag: :foo', 'foo'
include_examples 'does not set any flags as used', 'deduplicate :delayed'
end
-
- describe "tracking of usage data metrics known events happens at the beginning of inspection" do
- let(:usage_data_counters_known_event_feature_flags) { ['an_event_feature_flag'] }
-
- before do
- allow(cop).to receive(:usage_data_counters_known_event_feature_flags).and_return(usage_data_counters_known_event_feature_flags)
- end
-
- include_examples 'sets flag as used', "FEATURE_FLAG = :foo", %w[foo an_event_feature_flag]
- end
end
diff --git a/spec/rubocop/cop/gitlab/service_response_spec.rb b/spec/rubocop/cop/gitlab/service_response_spec.rb
index 84cf0dbff52..f90c84701c6 100644
--- a/spec/rubocop/cop/gitlab/service_response_spec.rb
+++ b/spec/rubocop/cop/gitlab/service_response_spec.rb
@@ -4,8 +4,6 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/gitlab/service_response'
RSpec.describe RuboCop::Cop::Gitlab::ServiceResponse do
- subject(:cop) { described_class.new }
-
it 'does not flag the `http_status:` param on a homonym method' do
expect_no_offenses("MyClass.error(http_status: :ok)")
end
diff --git a/spec/rubocop/cop/graphql/authorize_types_spec.rb b/spec/rubocop/cop/graphql/authorize_types_spec.rb
index a30cd5a1688..932991c7b76 100644
--- a/spec/rubocop/cop/graphql/authorize_types_spec.rb
+++ b/spec/rubocop/cop/graphql/authorize_types_spec.rb
@@ -17,6 +17,28 @@ RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes do
TYPE
end
+ it 'adds add an offense when authorize has no arguments' do
+ expect_offense(<<~TYPE.strip)
+ module Types
+ class AType < SuperClassWithFields
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add an `authorize :ability` call to the type: https://docs.gitlab.com/ee/development/graphql_guide/authorization.html#type-authorization
+ authorize
+ end
+ end
+ TYPE
+ end
+
+ it 'adds add an offense when authorize is empty' do
+ expect_offense(<<~TYPE.strip)
+ module Types
+ class AType < SuperClassWithFields
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add an `authorize :ability` call to the type: https://docs.gitlab.com/ee/development/graphql_guide/authorization.html#type-authorization
+ authorize []
+ end
+ end
+ TYPE
+ end
+
it 'does not add an offense for classes that have an authorize call' do
expect_no_offenses(<<~TYPE.strip)
module Types
diff --git a/spec/rubocop/cop/lint/last_keyword_argument_spec.rb b/spec/rubocop/cop/lint/last_keyword_argument_spec.rb
index 53f19cd01ee..edd54a40b79 100644
--- a/spec/rubocop/cop/lint/last_keyword_argument_spec.rb
+++ b/spec/rubocop/cop/lint/last_keyword_argument_spec.rb
@@ -3,7 +3,7 @@
require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/lint/last_keyword_argument'
-RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument, :ruby27, feature_category: :not_owned do
+RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument, :ruby27, feature_category: :shared do
before do
described_class.instance_variable_set(:@keyword_warnings, nil)
allow(Dir).to receive(:glob).and_call_original
diff --git a/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb b/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb
index 7cc88946cf1..c2f0053718a 100644
--- a/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb
+++ b/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb
@@ -4,8 +4,6 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/migration/add_columns_to_wide_tables'
RSpec.describe RuboCop::Cop::Migration::AddColumnsToWideTables do
- let(:cop) { described_class.new }
-
context 'when outside of a migration' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY)
diff --git a/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb b/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
index aa39f5f1603..98cfcb5c2e2 100644
--- a/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
+++ b/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
@@ -4,8 +4,6 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/migration/add_concurrent_foreign_key'
RSpec.describe RuboCop::Cop::Migration::AddConcurrentForeignKey do
- let(:cop) { described_class.new }
-
context 'when outside of a migration' do
it 'does not register any offenses' do
expect_no_offenses('def up; add_foreign_key(:projects, :users, column: :user_id); end')
diff --git a/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb b/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb
index a6a072e2caf..032cc12ab94 100644
--- a/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb
+++ b/spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb
@@ -78,30 +78,6 @@ RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns do
end
RUBY
end
-
- context 'for migrations before 2021_09_10_00_00_00' do
- it 'when limit: attribute is used (which is not supported yet for this version): registers an offense' do
- allow(cop).to receive(:version).and_return(described_class::TEXT_LIMIT_ATTRIBUTE_ALLOWED_SINCE - 5)
-
- expect_offense(<<~RUBY)
- class TestTextLimits < ActiveRecord::Migration[6.0]
- def up
- create_table :test_text_limit_attribute do |t|
- t.integer :test_id, null: false
- t.text :name, limit: 100
- ^^^^ Text columns should always have a limit set (255 is suggested). Using limit: is not supported in this version. You can add a limit to a `text` column by using `add_text_limit` or `.text_limit` inside `create_table`
- end
-
- create_table_with_constraints :test_text_limit_attribute do |t|
- t.integer :test_id, null: false
- t.text :name, limit: 100
- ^^^^ Text columns should always have a limit set (255 is suggested). Using limit: is not supported in this version. You can add a limit to a `text` column by using `add_text_limit` or `.text_limit` inside `create_table`
- end
- end
- end
- RUBY
- end
- end
end
context 'when text array columns are defined without a limit' do
diff --git a/spec/rubocop/cop/migration/add_reference_spec.rb b/spec/rubocop/cop/migration/add_reference_spec.rb
index bb3fe7068b4..7e6d14261c8 100644
--- a/spec/rubocop/cop/migration/add_reference_spec.rb
+++ b/spec/rubocop/cop/migration/add_reference_spec.rb
@@ -4,8 +4,6 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/migration/add_reference'
RSpec.describe RuboCop::Cop::Migration::AddReference do
- let(:cop) { described_class.new }
-
context 'when outside of a migration' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY)
diff --git a/spec/rubocop/cop/migration/background_migrations_spec.rb b/spec/rubocop/cop/migration/background_migrations_spec.rb
index 681bbd84562..78c38f669ad 100644
--- a/spec/rubocop/cop/migration/background_migrations_spec.rb
+++ b/spec/rubocop/cop/migration/background_migrations_spec.rb
@@ -4,8 +4,6 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/migration/background_migrations'
RSpec.describe RuboCop::Cop::Migration::BackgroundMigrations do
- let(:cop) { described_class.new }
-
context 'when queue_background_migration_jobs_by_range_at_intervals is used' do
it 'registers an offense' do
expect_offense(<<~RUBY)
diff --git a/spec/rubocop/cop/migration/batch_migrations_post_only_spec.rb b/spec/rubocop/cop/migration/batch_migrations_post_only_spec.rb
index b5e2e83e788..a33557dc1ce 100644
--- a/spec/rubocop/cop/migration/batch_migrations_post_only_spec.rb
+++ b/spec/rubocop/cop/migration/batch_migrations_post_only_spec.rb
@@ -4,8 +4,6 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/migration/batch_migrations_post_only'
RSpec.describe RuboCop::Cop::Migration::BatchMigrationsPostOnly do
- let(:cop) { described_class.new }
-
before do
allow(cop).to receive(:in_post_deployment_migration?).and_return post_migration?
end
diff --git a/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb b/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb
index 072edb5827b..feea5cb3958 100644
--- a/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb
+++ b/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb
@@ -4,8 +4,6 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/migration/create_table_with_foreign_keys'
RSpec.describe RuboCop::Cop::Migration::CreateTableWithForeignKeys do
- let(:cop) { described_class.new }
-
context 'outside of a migration' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY)
@@ -148,9 +146,11 @@ RSpec.describe RuboCop::Cop::Migration::CreateTableWithForeignKeys do
users
web_hook_logs
].each do |table|
- let(:table_name) { table }
+ context "with #{table}" do
+ let(:table_name) { table }
- it_behaves_like 'target to high traffic table', dsl_method, table
+ it_behaves_like 'target to high traffic table', dsl_method, table
+ end
end
end
diff --git a/spec/rubocop/cop/migration/schedule_async_spec.rb b/spec/rubocop/cop/migration/schedule_async_spec.rb
index 59e03db07c0..30f774c48b0 100644
--- a/spec/rubocop/cop/migration/schedule_async_spec.rb
+++ b/spec/rubocop/cop/migration/schedule_async_spec.rb
@@ -5,7 +5,6 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/migration/schedule_async'
RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
- let(:cop) { described_class.new }
let(:source) do
<<~SOURCE
def up
diff --git a/spec/rubocop/cop/migration/update_column_in_batches_spec.rb b/spec/rubocop/cop/migration/update_column_in_batches_spec.rb
index 005d3fb6b2a..25381fc0281 100644
--- a/spec/rubocop/cop/migration/update_column_in_batches_spec.rb
+++ b/spec/rubocop/cop/migration/update_column_in_batches_spec.rb
@@ -5,7 +5,6 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/migration/update_column_in_batches'
RSpec.describe RuboCop::Cop::Migration::UpdateColumnInBatches do
- let(:cop) { described_class.new }
let(:tmp_rails_root) { rails_root_join('tmp', 'rails_root') }
let(:migration_code) do
<<-END
diff --git a/spec/rubocop/cop/rspec/avoid_conditional_statements_spec.rb b/spec/rubocop/cop/rspec/avoid_conditional_statements_spec.rb
new file mode 100644
index 00000000000..3f45f660aa5
--- /dev/null
+++ b/spec/rubocop/cop/rspec/avoid_conditional_statements_spec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+
+require_relative '../../../../rubocop/cop/rspec/avoid_conditional_statements'
+
+RSpec.describe RuboCop::Cop::RSpec::AvoidConditionalStatements, feature_category: :tooling do
+ context 'when using conditionals' do
+ it 'flags if conditional' do
+ expect_offense(<<~RUBY)
+ if page.has_css?('[data-testid="begin-commit-button"]')
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't use `if` conditional statement in specs, it might create flakiness. See https://gitlab.com/gitlab-org/gitlab/-/issues/385304#note_1345437109
+ find('[data-testid="begin-commit-button"]').click
+ end
+ RUBY
+ end
+
+ it 'flags unless conditional' do
+ expect_offense(<<~RUBY)
+ RSpec.describe 'Multi-file editor new directory', :js, feature_category: :web_ide do
+ it 'creates directory in current directory' do
+ unless page.has_css?('[data-testid="begin-commit-button"]')
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't use `unless` conditional statement in specs, it might create flakiness. See https://gitlab.com/gitlab-org/gitlab/-/issues/385304#note_1345437109
+ find('[data-testid="begin-commit-button"]').click
+ end
+ end
+ end
+ RUBY
+ end
+
+ it 'flags ternary operator' do
+ expect_offense(<<~RUBY)
+ RSpec.describe 'Multi-file editor new directory', :js, feature_category: :web_ide do
+ it 'creates directory in current directory' do
+ user.present ? user : nil
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Don't use `user.present ? user : nil` conditional statement in specs, it might create flakiness. See https://gitlab.com/gitlab-org/gitlab/-/issues/385304#note_1345437109
+ end
+ end
+ RUBY
+ end
+ end
+end
diff --git a/spec/rubocop/cop/rspec/avoid_test_prof_spec.rb b/spec/rubocop/cop/rspec/avoid_test_prof_spec.rb
index b180134b226..db8c7b1d783 100644
--- a/spec/rubocop/cop/rspec/avoid_test_prof_spec.rb
+++ b/spec/rubocop/cop/rspec/avoid_test_prof_spec.rb
@@ -5,7 +5,7 @@ require 'rspec-parameterized'
require_relative '../../../../rubocop/cop/rspec/avoid_test_prof'
-RSpec.describe RuboCop::Cop::RSpec::AvoidTestProf, feature_category: :not_owned do
+RSpec.describe RuboCop::Cop::RSpec::AvoidTestProf, feature_category: :shared do
using RSpec::Parameterized::TableSyntax
context 'when there are offenses' do
diff --git a/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb b/spec/rubocop/cop/rspec/httparty_basic_auth_spec.rb
index 537a7a9a7e9..c7f4c61b501 100644
--- a/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb
+++ b/spec/rubocop/cop/rspec/httparty_basic_auth_spec.rb
@@ -4,7 +4,7 @@ require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/rspec/httparty_basic_auth'
-RSpec.describe RuboCop::Cop::RSpec::HTTPartyBasicAuth do
+RSpec.describe RuboCop::Cop::RSpec::HTTPartyBasicAuth, feature_category: :shared do
context 'when passing `basic_auth: { user: ... }`' do
it 'registers an offense and corrects', :aggregate_failures do
expect_offense(<<~SOURCE, 'spec/foo.rb')
diff --git a/spec/rubocop/cop/rspec/invalid_feature_category_spec.rb b/spec/rubocop/cop/rspec/invalid_feature_category_spec.rb
index 0d2fd029a13..e5287f7105e 100644
--- a/spec/rubocop/cop/rspec/invalid_feature_category_spec.rb
+++ b/spec/rubocop/cop/rspec/invalid_feature_category_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe RuboCop::Cop::RSpec::InvalidFeatureCategory, feature_category: :t
it 'flags invalid feature category in nested context' do
expect_offense(<<~RUBY, valid: valid_category, invalid: invalid_category)
- RSpec.describe 'foo', feature_category: :%{valid} do
+ RSpec.describe 'foo', feature_category: :"%{valid}" do
context 'bar', foo: :bar, feature_category: :%{invalid} do
^^{invalid} Please use a valid feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples.
end
@@ -27,7 +27,7 @@ RSpec.describe RuboCop::Cop::RSpec::InvalidFeatureCategory, feature_category: :t
it 'flags invalid feature category in examples' do
expect_offense(<<~RUBY, valid: valid_category, invalid: invalid_category)
- RSpec.describe 'foo', feature_category: :%{valid} do
+ RSpec.describe 'foo', feature_category: :"%{valid}" do
it 'bar', feature_category: :%{invalid} do
^^{invalid} Please use a valid feature category. See https://docs.gitlab.com/ee/development/feature_categorization/#rspec-examples.
end
@@ -37,9 +37,9 @@ RSpec.describe RuboCop::Cop::RSpec::InvalidFeatureCategory, feature_category: :t
it 'does not flag if feature category is valid' do
expect_no_offenses(<<~RUBY)
- RSpec.describe 'foo', feature_category: :#{valid_category} do
- context 'bar', feature_category: :#{valid_category} do
- it 'baz', feature_category: :#{valid_category} do
+ RSpec.describe 'foo', feature_category: :"#{valid_category}" do
+ context 'bar', feature_category: :"#{valid_category}" do
+ it 'baz', feature_category: :"#{valid_category}" do
end
end
end
@@ -50,8 +50,8 @@ RSpec.describe RuboCop::Cop::RSpec::InvalidFeatureCategory, feature_category: :t
mistyped = make_typo(valid_category)
expect_offense(<<~RUBY, invalid: mistyped, valid: valid_category)
- RSpec.describe 'foo', feature_category: :%{invalid} do
- ^^{invalid} Please use a valid feature category. Did you mean `:%{valid}`? See [...]
+ RSpec.describe 'foo', feature_category: :"%{invalid}" do
+ ^^^^{invalid} Please use a valid feature category. Did you mean `:%{valid}`? See [...]
end
RUBY
end
diff --git a/spec/rubocop/cop/rspec/misspelled_aggregate_failures_spec.rb b/spec/rubocop/cop/rspec/misspelled_aggregate_failures_spec.rb
new file mode 100644
index 00000000000..c551c03b896
--- /dev/null
+++ b/spec/rubocop/cop/rspec/misspelled_aggregate_failures_spec.rb
@@ -0,0 +1,136 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+require 'rspec-parameterized'
+
+require_relative '../../../../rubocop/cop/rspec/misspelled_aggregate_failures'
+
+RSpec.describe RuboCop::Cop::RSpec::MisspelledAggregateFailures, feature_category: :shared do
+ shared_examples 'misspelled tag' do |misspelled|
+ it 'flags and auto-corrects misspelled tags in describe' do
+ expect_offense(<<~'RUBY', misspelled: misspelled)
+ RSpec.describe 'a feature', :%{misspelled} do
+ ^^{misspelled} Use `:aggregate_failures` to aggregate failures.
+ describe 'inner', :%{misspelled} do
+ ^^{misspelled} Use `:aggregate_failures` to aggregate failures.
+ end
+ end
+ RUBY
+
+ expect_correction(<<~'RUBY')
+ RSpec.describe 'a feature', :aggregate_failures do
+ describe 'inner', :aggregate_failures do
+ end
+ end
+ RUBY
+ end
+
+ it 'flags and auto-corrects misspelled tags in context' do
+ expect_offense(<<~'RUBY', misspelled: misspelled)
+ context 'a feature', :%{misspelled} do
+ ^^{misspelled} Use `:aggregate_failures` to aggregate failures.
+ end
+ RUBY
+
+ expect_correction(<<~'RUBY')
+ context 'a feature', :aggregate_failures do
+ end
+ RUBY
+ end
+
+ it 'flags and auto-corrects misspelled tags in examples' do
+ expect_offense(<<~'RUBY', misspelled: misspelled)
+ it 'aggregates', :%{misspelled} do
+ ^^{misspelled} Use `:aggregate_failures` to aggregate failures.
+ end
+
+ specify :%{misspelled} do
+ ^^{misspelled} Use `:aggregate_failures` to aggregate failures.
+ end
+
+ it :%{misspelled} do
+ ^^{misspelled} Use `:aggregate_failures` to aggregate failures.
+ end
+ RUBY
+
+ expect_correction(<<~'RUBY')
+ it 'aggregates', :aggregate_failures do
+ end
+
+ specify :aggregate_failures do
+ end
+
+ it :aggregate_failures do
+ end
+ RUBY
+ end
+
+ it 'flags and auto-corrects misspelled tags in any order' do
+ expect_offense(<<~'RUBY', misspelled: misspelled)
+ it 'aggregates', :foo, :%{misspelled} do
+ ^^{misspelled} Use `:aggregate_failures` to aggregate failures.
+ end
+
+ it 'aggregates', :%{misspelled}, :bar do
+ ^^{misspelled} Use `:aggregate_failures` to aggregate failures.
+ end
+ RUBY
+
+ expect_correction(<<~'RUBY')
+ it 'aggregates', :foo, :aggregate_failures do
+ end
+
+ it 'aggregates', :aggregate_failures, :bar do
+ end
+ RUBY
+ end
+ end
+
+ shared_examples 'legit tag' do |legit_tag|
+ it 'does not flag' do
+ expect_no_offenses(<<~RUBY)
+ RSpec.describe 'a feature', :#{legit_tag} do
+ end
+
+ it 'is ok', :#{legit_tag} do
+ end
+ RUBY
+ end
+ end
+
+ context 'with misspelled tags' do
+ where(:tag) do
+ # From https://gitlab.com/gitlab-org/gitlab/-/issues/396356#list
+ %w[
+ aggregate_errors
+ aggregate_failure
+ aggregated_failures
+ aggregate_results
+ aggregated_errors
+ aggregates_failures
+ aggregate_failues
+
+ aggregate_bar
+ aggregate_foo
+ ]
+ end
+
+ with_them do
+ it_behaves_like 'misspelled tag', params[:tag]
+ end
+ end
+
+ context 'with legit tags' do
+ where(:tag) do
+ %w[
+ aggregate
+ aggregations
+ aggregate_two_underscores
+ ]
+ end
+
+ with_them do
+ it_behaves_like 'legit tag', params[:tag]
+ end
+ end
+end
diff --git a/spec/rubocop/cop/rspec/shared_groups_metadata_spec.rb b/spec/rubocop/cop/rspec/shared_groups_metadata_spec.rb
new file mode 100644
index 00000000000..3dd568e7dcd
--- /dev/null
+++ b/spec/rubocop/cop/rspec/shared_groups_metadata_spec.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+require 'rspec-parameterized'
+
+require_relative '../../../../rubocop/cop/rspec/shared_groups_metadata'
+
+RSpec.describe RuboCop::Cop::RSpec::SharedGroupsMetadata, feature_category: :tooling do
+ context 'with hash metadata' do
+ it 'flags metadata in shared example' do
+ expect_offense(<<~RUBY)
+ RSpec.shared_examples 'foo', feature_category: :shared do
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid using metadata on shared examples and shared context. They might cause flaky tests. See https://gitlab.com/gitlab-org/gitlab/-/issues/404388
+ end
+
+ shared_examples 'foo', feature_category: :shared do
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid using metadata on shared examples and shared context. They might cause flaky tests. See https://gitlab.com/gitlab-org/gitlab/-/issues/404388
+ end
+ RUBY
+ end
+
+ it 'flags metadata in shared context' do
+ expect_offense(<<~RUBY)
+ RSpec.shared_context 'foo', feature_category: :shared do
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid using metadata on shared examples and shared context. They might cause flaky tests. See https://gitlab.com/gitlab-org/gitlab/-/issues/404388
+ end
+
+ shared_context 'foo', feature_category: :shared do
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid using metadata on shared examples and shared context. They might cause flaky tests. See https://gitlab.com/gitlab-org/gitlab/-/issues/404388
+ end
+ RUBY
+ end
+ end
+
+ context 'with symbol metadata' do
+ it 'flags metadata in shared example' do
+ expect_offense(<<~RUBY)
+ RSpec.shared_examples 'foo', :aggregate_failures do
+ ^^^^^^^^^^^^^^^^^^^ Avoid using metadata on shared examples and shared context. They might cause flaky tests. See https://gitlab.com/gitlab-org/gitlab/-/issues/404388
+ end
+
+ shared_examples 'foo', :aggregate_failures do
+ ^^^^^^^^^^^^^^^^^^^ Avoid using metadata on shared examples and shared context. They might cause flaky tests. See https://gitlab.com/gitlab-org/gitlab/-/issues/404388
+ end
+ RUBY
+ end
+
+ it 'flags metadata in shared context' do
+ expect_offense(<<~RUBY)
+ RSpec.shared_context 'foo', :aggregate_failures do
+ ^^^^^^^^^^^^^^^^^^^ Avoid using metadata on shared examples and shared context. They might cause flaky tests. See https://gitlab.com/gitlab-org/gitlab/-/issues/404388
+ end
+
+ shared_context 'foo', :aggregate_failures do
+ ^^^^^^^^^^^^^^^^^^^ Avoid using metadata on shared examples and shared context. They might cause flaky tests. See https://gitlab.com/gitlab-org/gitlab/-/issues/404388
+ end
+ RUBY
+ end
+ end
+
+ it 'does not flag if feature category is missing' do
+ expect_no_offenses(<<~RUBY)
+ RSpec.shared_examples 'foo' do
+ end
+
+ shared_examples 'foo' do
+ end
+ RUBY
+ end
+end
diff --git a/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb b/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb
deleted file mode 100644
index b687e91601c..00000000000
--- a/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# frozen_string_literal: true
-
-require 'rubocop_spec_helper'
-
-require_relative '../../../rubocop/cop/ruby_interpolation_in_translation'
-
-# Disabling interpolation check as we deliberately want to have #{} in strings.
-# rubocop:disable Lint/InterpolationCheck
-RSpec.describe RuboCop::Cop::RubyInterpolationInTranslation do
- let(:msg) { "Don't use ruby interpolation \#{} inside translated strings, instead use %{}" }
-
- it 'does not add an offense for a regular messages' do
- expect_no_offenses('_("Hello world")')
- end
-
- it 'adds the correct offense when using interpolation in a string' do
- expect_offense(<<~CODE)
- _("Hello \#{world}")
- ^^^^^ #{msg}
- ^^^^^^^^ #{msg}
- CODE
- end
-
- it 'detects when using a ruby interpolation in the first argument of a pluralized string' do
- expect_offense(<<~CODE)
- n_("Hello \#{world}", "Hello world")
- ^^^^^ #{msg}
- ^^^^^^^^ #{msg}
- CODE
- end
-
- it 'detects when using a ruby interpolation in the second argument of a pluralized string' do
- expect_offense(<<~CODE)
- n_("Hello world", "Hello \#{world}")
- ^^^^^ #{msg}
- ^^^^^^^^ #{msg}
- CODE
- end
-
- it 'detects when using interpolation in a namespaced translation' do
- expect_offense(<<~CODE)
- s_("Hello|\#{world}")
- ^^^^^ #{msg}
- ^^^^^^^^ #{msg}
- CODE
- end
-end
-# rubocop:enable Lint/InterpolationCheck
diff --git a/spec/rubocop/cop/search/namespaced_class_spec.rb b/spec/rubocop/cop/search/namespaced_class_spec.rb
new file mode 100644
index 00000000000..6e10909389e
--- /dev/null
+++ b/spec/rubocop/cop/search/namespaced_class_spec.rb
@@ -0,0 +1,100 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+require_relative '../../../../rubocop/cop/search/namespaced_class'
+
+RSpec.describe RuboCop::Cop::Search::NamespacedClass, feature_category: :global_search do
+ %w[Search Zoekt Elastic].each do |keyword|
+ context 'when Search root namespace is not used' do
+ it 'flags a class definition without Search namespace' do
+ expect_offense(<<~'SOURCE', keyword: keyword, msg: described_class::MSG)
+ class My%{keyword}Class
+ ^^^{keyword}^^^^^ %{msg}
+ end
+ SOURCE
+
+ expect_offense(<<~'SOURCE', keyword: keyword, msg: described_class::MSG)
+ class %{keyword}::MyClass < ApplicationRecord
+ ^{keyword}^^^^^^^^^ %{msg}
+ def some_method
+ true
+ end
+ end
+ SOURCE
+
+ expect_offense(<<~'SOURCE', keyword: keyword, msg: described_class::MSG)
+ class MyClass < %{keyword}::Class
+ ^^^^^^^ %{msg}
+ def some_method
+ true
+ end
+ end
+ SOURCE
+ end
+
+ it "flags a class definition with #{keyword} in root namespace module" do
+ expect_offense(<<~'SOURCE', keyword: keyword, msg: described_class::MSG)
+ module %{keyword}Module
+ class MyClass < ApplicationRecord
+ ^^^^^^^ %{msg}
+ def some_method
+ true
+ end
+ end
+ end
+ SOURCE
+ end
+
+ it 'flags a module in EE module' do
+ expect_offense(<<~'SOURCE', keyword: keyword, msg: described_class::MSG)
+ module EE
+ module %{keyword}Controller
+ ^{keyword}^^^^^^^^^^ %{msg}
+ def some_method
+ true
+ end
+ end
+ end
+ SOURCE
+ end
+ end
+
+ context 'when Search root namespace is used' do
+ it 'does not flag a class definition with Search as root namespace module' do
+ expect_no_offenses(<<~SOURCE, keyword: keyword)
+ module Search
+ class %{keyword}::MyClass < ApplicationRecord
+ def some_method
+ true
+ end
+ end
+ end
+ SOURCE
+ end
+
+ it 'does not a flag a class definition with Search as root namespace inline' do
+ expect_no_offenses(<<~SOURCE, keyword: keyword)
+ class Search::%{keyword}::MyClass < ApplicationRecord
+ def some_method
+ true
+ end
+ end
+ SOURCE
+ end
+
+ it 'does not a flag a class definition with Search as root namespace in EE' do
+ expect_no_offenses(<<~SOURCE, keyword: keyword)
+ module EE
+ module Search
+ class %{keyword}::MyClass < ApplicationRecord
+ def some_method
+ true
+ end
+ end
+ end
+ end
+ SOURCE
+ end
+ end
+ end
+end
diff --git a/spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb b/spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb
index 7b6578a0744..f41a441d6a6 100644
--- a/spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb
+++ b/spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb
@@ -3,46 +3,95 @@
require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/sidekiq_load_balancing/worker_data_consistency'
-RSpec.describe RuboCop::Cop::SidekiqLoadBalancing::WorkerDataConsistency do
- before do
- allow(cop)
- .to receive(:in_worker?)
- .and_return(true)
- end
+RSpec.describe RuboCop::Cop::SidekiqLoadBalancing::WorkerDataConsistency, feature_category: :scalability do
+ context 'when data_consistency is not set' do
+ it 'adds an offense when not defining data_consistency' do
+ expect_offense(<<~CODE)
+ class SomeWorker
+ ^^^^^^^^^^^^^^^^ Should define data_consistency expectation.[...]
+ include ApplicationWorker
- it 'adds an offense when not defining data_consistency' do
- expect_offense(<<~CODE)
- class SomeWorker
- ^^^^^^^^^^^^^^^^ Should define data_consistency expectation.[...]
- include ApplicationWorker
-
- queue_namespace :pipeline_hooks
- feature_category :continuous_integration
- urgency :high
- end
- CODE
- end
+ queue_namespace :pipeline_hooks
+ feature_category :continuous_integration
+ urgency :high
+ end
+ CODE
+ end
+
+ it 'adds no offense when defining data_consistency' do
+ expect_no_offenses(<<~CODE)
+ class SomeWorker
+ include ApplicationWorker
- it 'adds no offense when defining data_consistency' do
- expect_no_offenses(<<~CODE)
- class SomeWorker
- include ApplicationWorker
-
- queue_namespace :pipeline_hooks
- feature_category :continuous_integration
- data_consistency :delayed
- urgency :high
- end
- CODE
+ queue_namespace :pipeline_hooks
+ feature_category :continuous_integration
+ data_consistency :delayed
+ urgency :high
+ end
+ CODE
+ end
+
+ it 'adds no offense when worker is not an ApplicationWorker' do
+ expect_no_offenses(<<~CODE)
+ class SomeWorker
+ queue_namespace :pipeline_hooks
+ feature_category :continuous_integration
+ urgency :high
+ end
+ CODE
+ end
end
- it 'adds no offense when worker is not an ApplicationWorker' do
- expect_no_offenses(<<~CODE)
- class SomeWorker
- queue_namespace :pipeline_hooks
- feature_category :continuous_integration
- urgency :high
- end
- CODE
+ context 'when data_consistency set to :always' do
+ it 'adds an offense when using `always` data_consistency' do
+ expect_offense(<<~CODE)
+ class SomeWorker
+ include ApplicationWorker
+ data_consistency :always
+ ^^^^^^^ Refrain from using `:always` if possible.[...]
+
+ queue_namespace :pipeline_hooks
+ feature_category :continuous_integration
+ urgency :high
+ end
+ CODE
+ end
+
+ it 'adds no offense when using `sticky` data_consistency' do
+ expect_no_offenses(<<~CODE)
+ class SomeWorker
+ include ApplicationWorker
+
+ data_consistency :sticky
+ queue_namespace :pipeline_hooks
+ feature_category :continuous_integration
+ urgency :high
+ end
+ CODE
+ end
+
+ it 'adds no offense when using `delayed` data_consistency' do
+ expect_no_offenses(<<~CODE)
+ class SomeWorker
+ include ApplicationWorker
+
+ data_consistency :delayed
+ queue_namespace :pipeline_hooks
+ feature_category :continuous_integration
+ urgency :high
+ end
+ CODE
+ end
+
+ it 'adds no offense when worker is not an ApplicationWorker' do
+ expect_no_offenses(<<~CODE)
+ class SomeWorker
+ data_consistency :always
+ queue_namespace :pipeline_hooks
+ feature_category :continuous_integration
+ urgency :high
+ end
+ CODE
+ end
end
end