From c014b6b4e5c33180dd5cbff1dd1bb4623d1eca80 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 14 Sep 2022 15:12:56 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/config/object_store_settings_spec.rb | 69 ---------------------- spec/controllers/concerns/continue_params_spec.rb | 2 + .../releases/stores/modules/detail/actions_spec.js | 26 ++++++++ spec/graphql/mutations/releases/create_spec.rb | 2 +- .../security/validators/schema_validator_spec.rb | 42 ++++++++----- spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb | 39 ++++++++---- spec/models/ci/pipeline_spec.rb | 42 +++++++++++++ spec/rubocop/code_reuse_helpers_spec.rb | 2 +- ...active_model_errors_direct_manipulation_spec.rb | 2 - .../cop/active_record_association_reload_spec.rb | 2 - spec/rubocop/cop/api/base_spec.rb | 2 - .../cop/api/grape_array_missing_coerce_spec.rb | 2 - spec/rubocop/cop/avoid_becomes_spec.rb | 2 - .../cop/avoid_break_from_strong_memoize_spec.rb | 2 - ...id_keyword_arguments_in_sidekiq_workers_spec.rb | 2 - spec/rubocop/cop/avoid_return_from_blocks_spec.rb | 2 - .../cop/avoid_route_redirect_leading_slash_spec.rb | 2 - spec/rubocop/cop/ban_catch_throw_spec.rb | 2 - spec/rubocop/cop/code_reuse/finder_spec.rb | 2 - spec/rubocop/cop/code_reuse/presenter_spec.rb | 2 - spec/rubocop/cop/code_reuse/serializer_spec.rb | 2 - spec/rubocop/cop/code_reuse/service_class_spec.rb | 2 - spec/rubocop/cop/code_reuse/worker_spec.rb | 2 - .../database/disable_referential_integrity_spec.rb | 2 - .../cop/database/establish_connection_spec.rb | 2 - .../cop/database/multiple_databases_spec.rb | 2 - .../cop/database/rescue_query_canceled_spec.rb | 2 - .../cop/database/rescue_statement_timeout_spec.rb | 2 - spec/rubocop/cop/default_scope_spec.rb | 2 - spec/rubocop/cop/destroy_all_spec.rb | 8 +-- spec/rubocop/cop/file_decompression_spec.rb | 2 - spec/rubocop/cop/filename_length_spec.rb | 2 - .../cop/gemspec/avoid_executing_git_spec.rb | 2 - .../avoid_feature_category_not_owned_spec.rb | 8 +-- .../gitlab/avoid_uploaded_file_from_params_spec.rb | 2 - spec/rubocop/cop/gitlab/bulk_insert_spec.rb | 2 - spec/rubocop/cop/gitlab/change_timezone_spec.rb | 2 - .../cop/gitlab/const_get_inherit_false_spec.rb | 2 - .../cop/gitlab/delegate_predicate_methods_spec.rb | 2 - .../gitlab/deprecate_track_redis_hll_event_spec.rb | 2 - .../cop/gitlab/duplicate_spec_location_spec.rb | 2 - .../cop/gitlab/event_store_subscriber_spec.rb | 2 - spec/rubocop/cop/gitlab/except_spec.rb | 2 - .../cop/gitlab/feature_available_usage_spec.rb | 2 - .../rubocop/cop/gitlab/finder_with_find_by_spec.rb | 2 - spec/rubocop/cop/gitlab/httparty_spec.rb | 2 - spec/rubocop/cop/gitlab/intersect_spec.rb | 2 - spec/rubocop/cop/gitlab/json_spec.rb | 2 - .../cop/gitlab/mark_used_feature_flags_spec.rb | 2 - .../gitlab/module_with_instance_variables_spec.rb | 2 - spec/rubocop/cop/gitlab/namespaced_class_spec.rb | 2 - .../rubocop/cop/gitlab/policy_rule_boolean_spec.rb | 2 - .../cop/gitlab/predicate_memoization_spec.rb | 2 - spec/rubocop/cop/gitlab/rails_logger_spec.rb | 2 - spec/rubocop/cop/gitlab/union_spec.rb | 2 - spec/rubocop/cop/graphql/authorize_types_spec.rb | 2 - spec/rubocop/cop/graphql/descriptions_spec.rb | 2 - spec/rubocop/cop/graphql/gid_expected_type_spec.rb | 2 - .../cop/graphql/graphql_name_position_spec.rb | 2 - spec/rubocop/cop/graphql/id_type_spec.rb | 2 - spec/rubocop/cop/graphql/json_type_spec.rb | 2 - spec/rubocop/cop/graphql/old_types_spec.rb | 2 - spec/rubocop/cop/graphql/resolver_type_spec.rb | 2 - .../cop/group_public_or_visible_to_user_spec.rb | 2 - spec/rubocop/cop/ignored_columns_spec.rb | 2 - spec/rubocop/cop/include_sidekiq_worker_spec.rb | 2 - .../cop/inject_enterprise_edition_module_spec.rb | 2 - .../rubocop/cop/lint/last_keyword_argument_spec.rb | 10 ++-- .../cop/migration/add_concurrent_index_spec.rb | 2 - spec/rubocop/cop/migration/add_index_spec.rb | 2 - .../migration/add_limit_to_text_columns_spec.rb | 2 - spec/rubocop/cop/migration/add_timestamps_spec.rb | 2 - .../background_migration_base_class_spec.rb | 2 - .../migration/background_migration_record_spec.rb | 2 - .../migration/complex_indexes_require_name_spec.rb | 2 - spec/rubocop/cop/migration/datetime_spec.rb | 2 - spec/rubocop/cop/migration/drop_table_spec.rb | 2 - .../rubocop/cop/migration/migration_record_spec.rb | 2 - ...ck_retries_with_disable_ddl_transaction_spec.rb | 2 - .../cop/migration/prevent_index_creation_spec.rb | 2 - spec/rubocop/cop/migration/prevent_strings_spec.rb | 2 - .../cop/migration/refer_to_index_by_name_spec.rb | 2 - spec/rubocop/cop/migration/remove_column_spec.rb | 2 - .../cop/migration/remove_concurrent_index_spec.rb | 2 - spec/rubocop/cop/migration/remove_index_spec.rb | 2 - .../cop/migration/safer_boolean_column_spec.rb | 2 - .../cop/migration/sidekiq_queue_migrate_spec.rb | 2 - spec/rubocop/cop/migration/timestamps_spec.rb | 2 - .../migration/versioned_migration_class_spec.rb | 2 - .../with_lock_retries_disallowed_method_spec.rb | 2 - .../with_lock_retries_with_change_spec.rb | 2 - .../active_record_subtransaction_methods_spec.rb | 2 - .../active_record_subtransactions_spec.rb | 2 - spec/rubocop/cop/performance/ar_count_each_spec.rb | 6 +- .../ar_exists_and_present_blank_spec.rb | 6 +- .../rubocop/cop/performance/readlines_each_spec.rb | 2 - .../cop/prefer_class_methods_over_module_spec.rb | 2 - spec/rubocop/cop/project_path_helper_spec.rb | 2 - .../cop/put_group_routes_under_scope_spec.rb | 2 - .../cop/put_project_routes_under_scope_spec.rb | 2 - .../cop/qa/ambiguous_page_object_name_spec.rb | 2 - spec/rubocop/cop/qa/element_with_pattern_spec.rb | 2 - spec/rubocop/cop/qa/selector_usage_spec.rb | 2 - spec/rubocop/cop/rspec/any_instance_of_spec.rb | 2 - spec/rubocop/cop/rspec/be_success_matcher_spec.rb | 2 - spec/rubocop/cop/rspec/env_assignment_spec.rb | 2 - .../cop/rspec/expect_gitlab_tracking_spec.rb | 2 - .../cop/rspec/factories_in_migration_specs_spec.rb | 2 - .../rspec/factory_bot/inline_association_spec.rb | 2 - .../cop/rspec/have_gitlab_http_status_spec.rb | 2 - .../rubocop/cop/rspec/htt_party_basic_auth_spec.rb | 2 - .../cop/rspec/modify_sidekiq_middleware_spec.rb | 2 - spec/rubocop/cop/rspec/timecop_freeze_spec.rb | 2 - spec/rubocop/cop/rspec/timecop_travel_spec.rb | 2 - .../cop/rspec/top_level_describe_path_spec.rb | 2 - spec/rubocop/cop/rspec/web_mock_enable_spec.rb | 2 - .../cop/ruby_interpolation_in_translation_spec.rb | 2 - spec/rubocop/cop/safe_params_spec.rb | 2 - .../scalability/bulk_perform_with_context_spec.rb | 2 - .../cop/scalability/cron_worker_context_spec.rb | 2 - spec/rubocop/cop/scalability/file_uploads_spec.rb | 2 - .../cop/scalability/idempotent_worker_spec.rb | 2 - .../worker_data_consistency_spec.rb | 2 - spec/rubocop/cop/sidekiq_options_queue_spec.rb | 2 - .../cop/static_translation_definition_spec.rb | 2 - .../distinct_count_by_large_foreign_key_spec.rb | 2 - .../usage_data/histogram_with_large_table_spec.rb | 2 - .../usage_data/instrumentation_superclass_spec.rb | 2 - spec/rubocop/cop/usage_data/large_table_spec.rb | 2 - spec/rubocop/cop/user_admin_spec.rb | 2 - spec/rubocop_spec_helper.rb | 3 + spec/services/releases/create_service_spec.rb | 22 +++++++ spec/spec_helper.rb | 3 - spec/support/rspec.rb | 3 + 134 files changed, 170 insertions(+), 357 deletions(-) (limited to 'spec') diff --git a/spec/config/object_store_settings_spec.rb b/spec/config/object_store_settings_spec.rb index 1555124fe03..8ddb5652dae 100644 --- a/spec/config/object_store_settings_spec.rb +++ b/spec/config/object_store_settings_spec.rb @@ -200,33 +200,6 @@ RSpec.describe ObjectStoreSettings do expect(settings.external_diffs['object_store']).to be_nil end end - - context 'with legacy config and legacy background upload is enabled' do - let(:legacy_settings) do - { - 'enabled' => true, - 'remote_directory' => 'some-bucket', - 'proxy_download' => false - } - end - - before do - stub_env(ObjectStoreSettings::LEGACY_BACKGROUND_UPLOADS_ENV, 'lfs') - settings.lfs['object_store'] = described_class.legacy_parse(legacy_settings, 'lfs') - end - - it 'enables background_upload and disables direct_upload' do - subject - - expect(settings.artifacts['object_store']).to be_nil - expect(settings.lfs['object_store']['remote_directory']).to eq('some-bucket') - expect(settings.lfs['object_store']['bucket_prefix']).to eq(nil) - # Enable background_upload if the environment variable is available - expect(settings.lfs['object_store']['direct_upload']).to eq(false) - expect(settings.lfs['object_store']['background_upload']).to eq(true) - expect(settings.external_diffs['object_store']).to be_nil - end - end end end @@ -266,48 +239,6 @@ RSpec.describe ObjectStoreSettings do expect(settings['remote_directory']).to eq 'gitlab' expect(settings['bucket_prefix']).to eq 'artifacts' end - - context 'legacy background upload environment variable is enabled' do - before do - stub_env(ObjectStoreSettings::LEGACY_BACKGROUND_UPLOADS_ENV, 'artifacts,lfs') - end - - it 'enables background_upload and disables direct_upload' do - original_settings = Settingslogic.new({ - 'enabled' => true, - 'remote_directory' => 'artifacts' - }) - - settings = described_class.legacy_parse(original_settings, 'artifacts') - - expect(settings['enabled']).to be true - expect(settings['direct_upload']).to be false - expect(settings['background_upload']).to be true - expect(settings['remote_directory']).to eq 'artifacts' - expect(settings['bucket_prefix']).to eq nil - end - end - - context 'legacy background upload environment variable is enabled for other types' do - before do - stub_env(ObjectStoreSettings::LEGACY_BACKGROUND_UPLOADS_ENV, 'uploads,lfs') - end - - it 'enables direct_upload and disables background_upload' do - original_settings = Settingslogic.new({ - 'enabled' => true, - 'remote_directory' => 'artifacts' - }) - - settings = described_class.legacy_parse(original_settings, 'artifacts') - - expect(settings['enabled']).to be true - expect(settings['direct_upload']).to be true - expect(settings['background_upload']).to be false - expect(settings['remote_directory']).to eq 'artifacts' - expect(settings['bucket_prefix']).to eq nil - end - end end describe '.split_bucket_prefix' do diff --git a/spec/controllers/concerns/continue_params_spec.rb b/spec/controllers/concerns/continue_params_spec.rb index c010e8ffbd0..ba600b8156a 100644 --- a/spec/controllers/concerns/continue_params_spec.rb +++ b/spec/controllers/concerns/continue_params_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe ContinueParams do let(:controller_class) do + # rubocop:disable Rails/ApplicationController Class.new(ActionController::Base) do include ContinueParams @@ -11,6 +12,7 @@ RSpec.describe ContinueParams do @request ||= Struct.new(:host, :port).new('test.host', 80) end end + # rubocop:enable Rails/ApplicationController end subject(:controller) { controller_class.new } diff --git a/spec/frontend/releases/stores/modules/detail/actions_spec.js b/spec/frontend/releases/stores/modules/detail/actions_spec.js index ce3b690213c..48fba3adb24 100644 --- a/spec/frontend/releases/stores/modules/detail/actions_spec.js +++ b/spec/frontend/releases/stores/modules/detail/actions_spec.js @@ -352,6 +352,32 @@ describe('Release edit/new actions', () => { }); }); + describe('when the GraphQL returns errors as data', () => { + beforeEach(() => { + gqClient.mutate.mockResolvedValue({ data: { releaseCreate: { errors: ['Yikes!'] } } }); + }); + + it(`commits ${types.RECEIVE_SAVE_RELEASE_ERROR} with an error object`, () => { + return testAction(actions.createRelease, undefined, state, [ + { + type: types.RECEIVE_SAVE_RELEASE_ERROR, + payload: expect.any(Error), + }, + ]); + }); + + it(`shows a flash message`, () => { + return actions + .createRelease({ commit: jest.fn(), dispatch: jest.fn(), state, getters: {} }) + .then(() => { + expect(createFlash).toHaveBeenCalledTimes(1); + expect(createFlash).toHaveBeenCalledWith({ + message: 'Yikes!', + }); + }); + }); + }); + describe('when the GraphQL network request fails', () => { beforeEach(() => { gqClient.mutate.mockRejectedValue(error); diff --git a/spec/graphql/mutations/releases/create_spec.rb b/spec/graphql/mutations/releases/create_spec.rb index b6b9449aa39..e7c25a20bad 100644 --- a/spec/graphql/mutations/releases/create_spec.rb +++ b/spec/graphql/mutations/releases/create_spec.rb @@ -135,7 +135,7 @@ RSpec.describe Mutations::Releases::Create do it 'has an access error' do subject - expect(resolve).to include(errors: ['Access Denied']) + expect(resolve).to include(errors: ['You are not allowed to create this tag as it is protected.']) end end end diff --git a/spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb b/spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb index 0f87ee82733..e730afc72b5 100644 --- a/spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb +++ b/spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb @@ -19,17 +19,36 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do } end + let(:report_data) do + { + 'scan' => { + 'analyzer' => { + 'id' => 'my-dast-analyzer', + 'name' => 'My DAST analyzer', + 'version' => '0.1.0', + 'vendor' => { 'name' => 'A DAST analyzer' } + }, + 'end_time' => '2020-01-28T03:26:02', + 'scanned_resources' => [], + 'scanner' => { + 'id' => 'my-dast-scanner', + 'name' => 'My DAST scanner', + 'version' => '0.2.0', + 'vendor' => { 'name' => 'A DAST scanner' } + }, + 'start_time' => '2020-01-28T03:26:01', + 'status' => 'success', + 'type' => 'dast' + }, + 'version' => report_version, + 'vulnerabilities' => [] + } + end + let(:validator) { described_class.new(report_type, report_data, report_version, project: project, scanner: scanner) } shared_examples 'report is valid' do context 'and the report is valid' do - let(:report_data) do - { - 'version' => report_version, - 'vulnerabilities' => [] - } - end - it { is_expected.to be_truthy } end end @@ -245,13 +264,6 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do shared_examples 'report is valid with no error' do context 'and the report is valid' do - let(:report_data) do - { - 'version' => report_version, - 'vulnerabilities' => [] - } - end - it { is_expected.to be_empty } end end @@ -278,7 +290,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do let(:expected_errors) do [ - 'root is missing required keys: vulnerabilities' + 'root is missing required keys: scan, vulnerabilities' ] end diff --git a/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb index e8eb3333b88..ee32661f267 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb @@ -83,19 +83,36 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Sequence do .with({ source: 'push' }, 0) end - it 'records active jobs by pipeline plan in a histogram' do - allow(command.metrics) - .to receive(:active_jobs_histogram) - .and_return(histogram) + describe 'active jobs by pipeline plan histogram' do + before do + allow(command.metrics) + .to receive(:active_jobs_histogram) + .and_return(histogram) + + pipeline = create(:ci_pipeline, :running, project: project) + create_list(:ci_build, 3, pipeline: pipeline) + create(:ci_bridge, pipeline: pipeline) + end - pipeline = create(:ci_pipeline, project: project, status: :running) - create(:ci_build, :finished, project: project, pipeline: pipeline) - create(:ci_build, :failed, project: project, pipeline: pipeline) - create(:ci_build, :running, project: project, pipeline: pipeline) - subject.build! + it 'counts all the active jobs' do + subject.build! - expect(histogram).to have_received(:observe) - .with(hash_including(plan: project.actual_plan_name), 3) + expect(histogram).to have_received(:observe) + .with(hash_including(plan: project.actual_plan_name), 4) + end + + context 'when feature flag ci_limit_active_jobs_early is disabled' do + before do + stub_feature_flags(ci_limit_active_jobs_early: false) + end + + it 'counts all the active builds' do + subject.build! + + expect(histogram).to have_received(:observe) + .with(hash_including(plan: project.actual_plan_name), 3) + end + end end end end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 29ff0641aa9..f93aeef4f23 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -466,6 +466,48 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do end end + describe '.jobs_count_in_alive_pipelines' do + before do + ::Ci::HasStatus::ALIVE_STATUSES.each do |status| + alive_pipeline = create(:ci_pipeline, status: status, project: project) + create(:ci_build, pipeline: alive_pipeline) + create(:ci_bridge, pipeline: alive_pipeline) + end + + completed_pipeline = create(:ci_pipeline, :success, project: project) + create(:ci_build, pipeline: completed_pipeline) + + old_pipeline = create(:ci_pipeline, :running, project: project, created_at: 2.days.ago) + create(:ci_build, pipeline: old_pipeline) + end + + it 'includes all jobs in alive pipelines created in the last 24 hours' do + expect(described_class.jobs_count_in_alive_pipelines) + .to eq(::Ci::HasStatus::ALIVE_STATUSES.count * 2) + end + end + + describe '.builds_count_in_alive_pipelines' do + before do + ::Ci::HasStatus::ALIVE_STATUSES.each do |status| + alive_pipeline = create(:ci_pipeline, status: status, project: project) + create(:ci_build, pipeline: alive_pipeline) + create(:ci_bridge, pipeline: alive_pipeline) + end + + completed_pipeline = create(:ci_pipeline, :success, project: project) + create(:ci_build, pipeline: completed_pipeline) + + old_pipeline = create(:ci_pipeline, :running, project: project, created_at: 2.days.ago) + create(:ci_build, pipeline: old_pipeline) + end + + it 'includes all builds in alive pipelines created in the last 24 hours' do + expect(described_class.builds_count_in_alive_pipelines) + .to eq(::Ci::HasStatus::ALIVE_STATUSES.count) + end + end + describe '#merge_request?' do let_it_be(:merge_request) { create(:merge_request) } let_it_be_with_reload(:pipeline) do diff --git a/spec/rubocop/code_reuse_helpers_spec.rb b/spec/rubocop/code_reuse_helpers_spec.rb index a8f935426e6..a112c9754f3 100644 --- a/spec/rubocop/code_reuse_helpers_spec.rb +++ b/spec/rubocop/code_reuse_helpers_spec.rb @@ -342,7 +342,7 @@ RSpec.describe RuboCop::CodeReuseHelpers do expect(cop) .to receive(:add_offense) - .with(send_node, location: :expression, message: 'oops') + .with(send_node, message: 'oops') cop.disallow_send_to(def_node, 'Finder', 'oops') end diff --git a/spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb b/spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb index 203c3b4d019..6be2f4945fd 100644 --- a/spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb +++ b/spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/active_model_errors_direct_manipulation' RSpec.describe RuboCop::Cop::ActiveModelErrorsDirectManipulation do - subject(:cop) { described_class.new } - context 'when modifying errors' do it 'registers an offense' do expect_offense(<<~PATTERN) diff --git a/spec/rubocop/cop/active_record_association_reload_spec.rb b/spec/rubocop/cop/active_record_association_reload_spec.rb index 8f5e40ba5dd..9f101b80d9a 100644 --- a/spec/rubocop/cop/active_record_association_reload_spec.rb +++ b/spec/rubocop/cop/active_record_association_reload_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/active_record_association_reload' RSpec.describe RuboCop::Cop::ActiveRecordAssociationReload do - subject(:cop) { described_class.new } - context 'when using ActiveRecord::Base' do it 'registers an offense on reload usage' do expect_offense(<<~PATTERN) diff --git a/spec/rubocop/cop/api/base_spec.rb b/spec/rubocop/cop/api/base_spec.rb index 3f87b6fd7a0..66e99b75643 100644 --- a/spec/rubocop/cop/api/base_spec.rb +++ b/spec/rubocop/cop/api/base_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/api/base' RSpec.describe RuboCop::Cop::API::Base do - subject(:cop) { described_class.new } - let(:corrected) do <<~CORRECTED class SomeAPI < ::API::Base diff --git a/spec/rubocop/cop/api/grape_array_missing_coerce_spec.rb b/spec/rubocop/cop/api/grape_array_missing_coerce_spec.rb index 5f310b68f18..1d1754df838 100644 --- a/spec/rubocop/cop/api/grape_array_missing_coerce_spec.rb +++ b/spec/rubocop/cop/api/grape_array_missing_coerce_spec.rb @@ -10,8 +10,6 @@ RSpec.describe RuboCop::Cop::API::GrapeArrayMissingCoerce do "https://github.com/ruby-grape/grape/blob/master/UPGRADING.md#ensure-that-array-types-have-explicit-coercions" end - subject(:cop) { described_class.new } - it 'adds an offense with a required parameter' do expect_offense(<<~TYPE) class SomeAPI < Grape::API::Instance diff --git a/spec/rubocop/cop/avoid_becomes_spec.rb b/spec/rubocop/cop/avoid_becomes_spec.rb index 4bb6c70c19f..d67b79329c9 100644 --- a/spec/rubocop/cop/avoid_becomes_spec.rb +++ b/spec/rubocop/cop/avoid_becomes_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/avoid_becomes' RSpec.describe RuboCop::Cop::AvoidBecomes do - subject(:cop) { described_class.new } - it 'flags the use of becomes with a constant parameter' do expect_offense(<<~CODE) foo.becomes(Project) diff --git a/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb b/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb index c66e2fb07b6..9b7d988cb24 100644 --- a/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb +++ b/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/avoid_break_from_strong_memoize' RSpec.describe RuboCop::Cop::AvoidBreakFromStrongMemoize do - subject(:cop) { described_class.new } - it 'flags violation for break inside strong_memoize' do expect_offense(<<~RUBY) strong_memoize(:result) do diff --git a/spec/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers_spec.rb b/spec/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers_spec.rb index 76999891212..eb2417a7eef 100644 --- a/spec/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers_spec.rb +++ b/spec/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers' RSpec.describe RuboCop::Cop::AvoidKeywordArgumentsInSidekiqWorkers do - subject(:cop) { described_class.new } - it 'flags violation for keyword arguments usage in perform method signature' do expect_offense(<<~RUBY) def perform(id:) diff --git a/spec/rubocop/cop/avoid_return_from_blocks_spec.rb b/spec/rubocop/cop/avoid_return_from_blocks_spec.rb index 67e7e7912f2..e35705ae791 100644 --- a/spec/rubocop/cop/avoid_return_from_blocks_spec.rb +++ b/spec/rubocop/cop/avoid_return_from_blocks_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/avoid_return_from_blocks' RSpec.describe RuboCop::Cop::AvoidReturnFromBlocks do - subject(:cop) { described_class.new } - it 'flags violation for return inside a block' do expect_offense(<<~RUBY) call do diff --git a/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb b/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb index 0205bc9f02a..377050eb301 100644 --- a/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb +++ b/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/avoid_route_redirect_leading_slash' RSpec.describe RuboCop::Cop::AvoidRouteRedirectLeadingSlash do - subject(:cop) { described_class.new } - before do allow(cop).to receive(:in_routes?).and_return(true) end diff --git a/spec/rubocop/cop/ban_catch_throw_spec.rb b/spec/rubocop/cop/ban_catch_throw_spec.rb index 9a829a94ef5..a41868410eb 100644 --- a/spec/rubocop/cop/ban_catch_throw_spec.rb +++ b/spec/rubocop/cop/ban_catch_throw_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/ban_catch_throw' RSpec.describe RuboCop::Cop::BanCatchThrow do - subject(:cop) { described_class.new } - it 'registers an offense when `catch` or `throw` are used' do expect_offense(<<~CODE) catch(:foo) { diff --git a/spec/rubocop/cop/code_reuse/finder_spec.rb b/spec/rubocop/cop/code_reuse/finder_spec.rb index 4e49b2c4f9f..8e285e3d988 100644 --- a/spec/rubocop/cop/code_reuse/finder_spec.rb +++ b/spec/rubocop/cop/code_reuse/finder_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/code_reuse/finder' RSpec.describe RuboCop::Cop::CodeReuse::Finder do - subject(:cop) { described_class.new } - it 'flags the use of a Finder inside another Finder' do allow(cop) .to receive(:in_finder?) diff --git a/spec/rubocop/cop/code_reuse/presenter_spec.rb b/spec/rubocop/cop/code_reuse/presenter_spec.rb index 804e61a4c6f..fb7a95f930d 100644 --- a/spec/rubocop/cop/code_reuse/presenter_spec.rb +++ b/spec/rubocop/cop/code_reuse/presenter_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/code_reuse/presenter' RSpec.describe RuboCop::Cop::CodeReuse::Presenter do - subject(:cop) { described_class.new } - it 'flags the use of a Presenter in a Service class' do allow(cop) .to receive(:in_service_class?) diff --git a/spec/rubocop/cop/code_reuse/serializer_spec.rb b/spec/rubocop/cop/code_reuse/serializer_spec.rb index 5ff01812ebb..b1f22c7b969 100644 --- a/spec/rubocop/cop/code_reuse/serializer_spec.rb +++ b/spec/rubocop/cop/code_reuse/serializer_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/code_reuse/serializer' RSpec.describe RuboCop::Cop::CodeReuse::Serializer do - subject(:cop) { described_class.new } - it 'flags the use of a Serializer in a Service class' do allow(cop) .to receive(:in_service_class?) diff --git a/spec/rubocop/cop/code_reuse/service_class_spec.rb b/spec/rubocop/cop/code_reuse/service_class_spec.rb index 5467df9a803..5792b86a535 100644 --- a/spec/rubocop/cop/code_reuse/service_class_spec.rb +++ b/spec/rubocop/cop/code_reuse/service_class_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/code_reuse/service_class' RSpec.describe RuboCop::Cop::CodeReuse::ServiceClass do - subject(:cop) { described_class.new } - it 'flags the use of a Service class in a Finder' do allow(cop) .to receive(:in_finder?) diff --git a/spec/rubocop/cop/code_reuse/worker_spec.rb b/spec/rubocop/cop/code_reuse/worker_spec.rb index 3b3a0788d7d..2df5ebc56fa 100644 --- a/spec/rubocop/cop/code_reuse/worker_spec.rb +++ b/spec/rubocop/cop/code_reuse/worker_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/code_reuse/worker' RSpec.describe RuboCop::Cop::CodeReuse::Worker do - subject(:cop) { described_class.new } - it 'flags the use of a worker in a controller' do allow(cop) .to receive(:in_controller?) diff --git a/spec/rubocop/cop/database/disable_referential_integrity_spec.rb b/spec/rubocop/cop/database/disable_referential_integrity_spec.rb index 25d5dc7cb1d..5d31e55e586 100644 --- a/spec/rubocop/cop/database/disable_referential_integrity_spec.rb +++ b/spec/rubocop/cop/database/disable_referential_integrity_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/database/disable_referential_integrity' RSpec.describe RuboCop::Cop::Database::DisableReferentialIntegrity do - subject(:cop) { described_class.new } - it 'does not flag the use of disable_referential_integrity with a send receiver' do expect_offense(<<~SOURCE) foo.disable_referential_integrity diff --git a/spec/rubocop/cop/database/establish_connection_spec.rb b/spec/rubocop/cop/database/establish_connection_spec.rb index 88bf16083e4..987f68def75 100644 --- a/spec/rubocop/cop/database/establish_connection_spec.rb +++ b/spec/rubocop/cop/database/establish_connection_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/database/establish_connection' RSpec.describe RuboCop::Cop::Database::EstablishConnection do - subject(:cop) { described_class.new } - it 'flags the use of ActiveRecord::Base.establish_connection' do expect_offense(<<~CODE) ActiveRecord::Base.establish_connection diff --git a/spec/rubocop/cop/database/multiple_databases_spec.rb b/spec/rubocop/cop/database/multiple_databases_spec.rb index a5061735848..124e8aaf39c 100644 --- a/spec/rubocop/cop/database/multiple_databases_spec.rb +++ b/spec/rubocop/cop/database/multiple_databases_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/database/multiple_databases' RSpec.describe RuboCop::Cop::Database::MultipleDatabases do - subject(:cop) { described_class.new } - it 'flags the use of ActiveRecord::Base.connection' do expect_offense(<<~SOURCE) ActiveRecord::Base.connection.inspect diff --git a/spec/rubocop/cop/database/rescue_query_canceled_spec.rb b/spec/rubocop/cop/database/rescue_query_canceled_spec.rb index 170fe06bb9e..2418b45e3bb 100644 --- a/spec/rubocop/cop/database/rescue_query_canceled_spec.rb +++ b/spec/rubocop/cop/database/rescue_query_canceled_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/database/rescue_query_canceled' RSpec.describe RuboCop::Cop::Database::RescueQueryCanceled do - subject(:cop) { described_class.new } - it 'flags the use of ActiveRecord::QueryCanceled' do expect_offense(<<~CODE) begin diff --git a/spec/rubocop/cop/database/rescue_statement_timeout_spec.rb b/spec/rubocop/cop/database/rescue_statement_timeout_spec.rb index 9048930860d..bfeba2b4d00 100644 --- a/spec/rubocop/cop/database/rescue_statement_timeout_spec.rb +++ b/spec/rubocop/cop/database/rescue_statement_timeout_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/database/rescue_statement_timeout' RSpec.describe RuboCop::Cop::Database::RescueStatementTimeout do - subject(:cop) { described_class.new } - it 'flags the use of ActiveRecord::StatementTimeout' do expect_offense(<<~CODE) begin diff --git a/spec/rubocop/cop/default_scope_spec.rb b/spec/rubocop/cop/default_scope_spec.rb index 3a0607c32b8..d1f26cdce46 100644 --- a/spec/rubocop/cop/default_scope_spec.rb +++ b/spec/rubocop/cop/default_scope_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/default_scope' RSpec.describe RuboCop::Cop::DefaultScope do - subject(:cop) { described_class.new } - it 'does not flag the use of default_scope with a send receiver' do expect_no_offenses('foo.default_scope') end diff --git a/spec/rubocop/cop/destroy_all_spec.rb b/spec/rubocop/cop/destroy_all_spec.rb index cdc1fbbb531..f984822a4e8 100644 --- a/spec/rubocop/cop/destroy_all_spec.rb +++ b/spec/rubocop/cop/destroy_all_spec.rb @@ -4,18 +4,16 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/destroy_all' RSpec.describe RuboCop::Cop::DestroyAll do - subject(:cop) { described_class.new } - it 'flags the use of destroy_all with a send receiver' do expect_offense(<<~CODE) - foo.destroy_all # rubocop: disable Cop/DestroyAll + foo.destroy_all ^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...] CODE end it 'flags the use of destroy_all with a constant receiver' do expect_offense(<<~CODE) - User.destroy_all # rubocop: disable Cop/DestroyAll + User.destroy_all ^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...] CODE end @@ -30,7 +28,7 @@ RSpec.describe RuboCop::Cop::DestroyAll do it 'flags the use of destroy_all with a local variable receiver' do expect_offense(<<~CODE) users = User.all - users.destroy_all # rubocop: disable Cop/DestroyAll + users.destroy_all ^^^^^^^^^^^^^^^^^ Use `delete_all` instead of `destroy_all`. [...] CODE end diff --git a/spec/rubocop/cop/file_decompression_spec.rb b/spec/rubocop/cop/file_decompression_spec.rb index 8b4aa8d57c3..19d71a2e85b 100644 --- a/spec/rubocop/cop/file_decompression_spec.rb +++ b/spec/rubocop/cop/file_decompression_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/file_decompression' RSpec.describe RuboCop::Cop::FileDecompression do - subject(:cop) { described_class.new } - it 'does not flag when using a system command not related to file decompression' do expect_no_offenses('system("ls")') end diff --git a/spec/rubocop/cop/filename_length_spec.rb b/spec/rubocop/cop/filename_length_spec.rb index d8d0affd9cc..1ea368d282f 100644 --- a/spec/rubocop/cop/filename_length_spec.rb +++ b/spec/rubocop/cop/filename_length_spec.rb @@ -5,8 +5,6 @@ require 'rubocop/rspec/support' require_relative '../../../rubocop/cop/filename_length' RSpec.describe RuboCop::Cop::FilenameLength do - subject(:cop) { described_class.new } - it 'does not flag files with names 100 characters long' do expect_no_offenses('puts "it does not matter"', 'a' * 100) end diff --git a/spec/rubocop/cop/gemspec/avoid_executing_git_spec.rb b/spec/rubocop/cop/gemspec/avoid_executing_git_spec.rb index c94fb9da113..6a1982d8101 100644 --- a/spec/rubocop/cop/gemspec/avoid_executing_git_spec.rb +++ b/spec/rubocop/cop/gemspec/avoid_executing_git_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gemspec/avoid_executing_git' RSpec.describe RuboCop::Cop::Gemspec::AvoidExecutingGit do - subject(:cop) { described_class.new } - it 'flags violation for executing git' do expect_offense(<<~RUBY) Gem::Specification.new do |gem| diff --git a/spec/rubocop/cop/gitlab/avoid_feature_category_not_owned_spec.rb b/spec/rubocop/cop/gitlab/avoid_feature_category_not_owned_spec.rb index 19a82231a80..9cacee5f75d 100644 --- a/spec/rubocop/cop/gitlab/avoid_feature_category_not_owned_spec.rb +++ b/spec/rubocop/cop/gitlab/avoid_feature_category_not_owned_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/avoid_feature_category_not_owned' RSpec.describe RuboCop::Cop::Gitlab::AvoidFeatureCategoryNotOwned do - subject(:cop) { described_class.new } - shared_examples 'defining feature category on a class' do it 'flags a method call on a class' do expect_offense(<<~SOURCE) @@ -31,7 +29,7 @@ RSpec.describe RuboCop::Cop::Gitlab::AvoidFeatureCategoryNotOwned do context 'in controllers' do before do - allow(subject).to receive(:in_controller?).and_return(true) + allow(cop).to receive(:in_controller?).and_return(true) end it_behaves_like 'defining feature category on a class' @@ -39,7 +37,7 @@ RSpec.describe RuboCop::Cop::Gitlab::AvoidFeatureCategoryNotOwned do context 'in workers' do before do - allow(subject).to receive(:in_worker?).and_return(true) + allow(cop).to receive(:in_worker?).and_return(true) end it_behaves_like 'defining feature category on a class' @@ -47,7 +45,7 @@ RSpec.describe RuboCop::Cop::Gitlab::AvoidFeatureCategoryNotOwned do context 'for grape endpoints' do before do - allow(subject).to receive(:in_api?).and_return(true) + allow(cop).to receive(:in_api?).and_return(true) end it_behaves_like 'defining feature category on a class' diff --git a/spec/rubocop/cop/gitlab/avoid_uploaded_file_from_params_spec.rb b/spec/rubocop/cop/gitlab/avoid_uploaded_file_from_params_spec.rb index bbdc6ca2470..09d5552d40c 100644 --- a/spec/rubocop/cop/gitlab/avoid_uploaded_file_from_params_spec.rb +++ b/spec/rubocop/cop/gitlab/avoid_uploaded_file_from_params_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/avoid_uploaded_file_from_params' RSpec.describe RuboCop::Cop::Gitlab::AvoidUploadedFileFromParams do - subject(:cop) { described_class.new } - context 'when using UploadedFile.from_params' do it 'flags its call' do expect_offense(<<~SOURCE) diff --git a/spec/rubocop/cop/gitlab/bulk_insert_spec.rb b/spec/rubocop/cop/gitlab/bulk_insert_spec.rb index 3cce93628fe..28fdd18b0f5 100644 --- a/spec/rubocop/cop/gitlab/bulk_insert_spec.rb +++ b/spec/rubocop/cop/gitlab/bulk_insert_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/bulk_insert' RSpec.describe RuboCop::Cop::Gitlab::BulkInsert do - subject(:cop) { described_class.new } - it 'flags the use of ApplicationRecord.legacy_bulk_insert' do expect_offense(<<~SOURCE) ApplicationRecord.legacy_bulk_insert('merge_request_diff_files', rows) diff --git a/spec/rubocop/cop/gitlab/change_timezone_spec.rb b/spec/rubocop/cop/gitlab/change_timezone_spec.rb index a3b5912e7e9..d5100cb662a 100644 --- a/spec/rubocop/cop/gitlab/change_timezone_spec.rb +++ b/spec/rubocop/cop/gitlab/change_timezone_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/change_timezone' RSpec.describe RuboCop::Cop::Gitlab::ChangeTimezone do - subject(:cop) { described_class.new } - context 'Time.zone=' do it 'registers an offense with no 2nd argument' do expect_offense(<<~PATTERN) diff --git a/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb index 1b13bcd4595..99cc9e0b469 100644 --- a/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb +++ b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/const_get_inherit_false' RSpec.describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do - subject(:cop) { described_class.new } - context 'Object.const_get' do it 'registers an offense with no 2nd argument and corrects' do expect_offense(<<~PATTERN) diff --git a/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb b/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb index f910e8a7a54..1b497954aee 100644 --- a/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb +++ b/spec/rubocop/cop/gitlab/delegate_predicate_methods_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/delegate_predicate_methods' RSpec.describe RuboCop::Cop::Gitlab::DelegatePredicateMethods do - subject(:cop) { described_class.new } - it 'registers offense for single predicate method with allow_nil:true' do expect_offense(<<~SOURCE) delegate :is_foo?, :do_foo, to: :bar, allow_nil: true 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 index a5370487794..eed30e11a98 100644 --- a/spec/rubocop/cop/gitlab/deprecate_track_redis_hll_event_spec.rb +++ b/spec/rubocop/cop/gitlab/deprecate_track_redis_hll_event_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/deprecate_track_redis_hll_event' RSpec.describe RuboCop::Cop::Gitlab::DeprecateTrackRedisHLLEvent do - subject(:cop) { described_class.new } - it 'does not flag the use of track_event' do expect_no_offenses('track_event :show, name: "p_analytics_insights"') end diff --git a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb index 1a108d4cd41..9a1639806c8 100644 --- a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb +++ b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/duplicate_spec_location' RSpec.describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do - subject(:cop) { described_class.new } - let(:rails_root) { '../../../../' } def full_path(path) diff --git a/spec/rubocop/cop/gitlab/event_store_subscriber_spec.rb b/spec/rubocop/cop/gitlab/event_store_subscriber_spec.rb index 9fe28481565..7c692d5aad4 100644 --- a/spec/rubocop/cop/gitlab/event_store_subscriber_spec.rb +++ b/spec/rubocop/cop/gitlab/event_store_subscriber_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/event_store_subscriber' RSpec.describe RuboCop::Cop::Gitlab::EventStoreSubscriber do - subject(:cop) { described_class.new } - context 'when an event store subscriber overrides #perform' do it 'registers an offense' do expect_offense(<<~WORKER) diff --git a/spec/rubocop/cop/gitlab/except_spec.rb b/spec/rubocop/cop/gitlab/except_spec.rb index 60359ffa8bb..47048b8f658 100644 --- a/spec/rubocop/cop/gitlab/except_spec.rb +++ b/spec/rubocop/cop/gitlab/except_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/except' RSpec.describe RuboCop::Cop::Gitlab::Except do - subject(:cop) { described_class.new } - it 'flags the use of Gitlab::SQL::Except.new' do expect_offense(<<~SOURCE) Gitlab::SQL::Except.new([foo]) diff --git a/spec/rubocop/cop/gitlab/feature_available_usage_spec.rb b/spec/rubocop/cop/gitlab/feature_available_usage_spec.rb index 5b56800cc1c..30edd33a318 100644 --- a/spec/rubocop/cop/gitlab/feature_available_usage_spec.rb +++ b/spec/rubocop/cop/gitlab/feature_available_usage_spec.rb @@ -6,8 +6,6 @@ require 'rubocop/rspec/support' require_relative '../../../../rubocop/cop/gitlab/feature_available_usage' RSpec.describe RuboCop::Cop::Gitlab::FeatureAvailableUsage do - subject(:cop) { described_class.new } - context 'no arguments given' do it 'does not flag the use of Gitlab::Sourcegraph.feature_available? with no arguments' do expect_no_offenses('Gitlab::Sourcegraph.feature_available?') diff --git a/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb b/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb index 29a93b96228..6e01ef1bdec 100644 --- a/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb +++ b/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/finder_with_find_by' RSpec.describe RuboCop::Cop::Gitlab::FinderWithFindBy do - subject(:cop) { described_class.new } - context 'when calling execute.find' do it 'registers an offense and corrects' do expect_offense(<<~CODE) diff --git a/spec/rubocop/cop/gitlab/httparty_spec.rb b/spec/rubocop/cop/gitlab/httparty_spec.rb index e1e72c11bd1..09204009d9b 100644 --- a/spec/rubocop/cop/gitlab/httparty_spec.rb +++ b/spec/rubocop/cop/gitlab/httparty_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/httparty' RSpec.describe RuboCop::Cop::Gitlab::HTTParty do # rubocop:disable RSpec/FilePath - subject(:cop) { described_class.new } - shared_examples('registering include offense') do it 'registers an offense when the class includes HTTParty' do expect_offense(source) diff --git a/spec/rubocop/cop/gitlab/intersect_spec.rb b/spec/rubocop/cop/gitlab/intersect_spec.rb index d2920c0b16b..c81dae9af97 100644 --- a/spec/rubocop/cop/gitlab/intersect_spec.rb +++ b/spec/rubocop/cop/gitlab/intersect_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/intersect' RSpec.describe RuboCop::Cop::Gitlab::Intersect do - subject(:cop) { described_class.new } - it 'flags the use of Gitlab::SQL::Intersect.new' do expect_offense(<<~SOURCE) Gitlab::SQL::Intersect.new([foo]) diff --git a/spec/rubocop/cop/gitlab/json_spec.rb b/spec/rubocop/cop/gitlab/json_spec.rb index c56b78c5750..e4ec107747d 100644 --- a/spec/rubocop/cop/gitlab/json_spec.rb +++ b/spec/rubocop/cop/gitlab/json_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/json' RSpec.describe RuboCop::Cop::Gitlab::Json do - subject(:cop) { described_class.new } - context 'when ::JSON is called' do it 'registers an offense' do expect_offense(<<~RUBY) 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 515620bd820..ac7e41dda44 100644 --- a/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb +++ b/spec/rubocop/cop/gitlab/mark_used_feature_flags_spec.rb @@ -10,8 +10,6 @@ RSpec.describe RuboCop::Cop::Gitlab::MarkUsedFeatureFlags do %w[a_feature_flag foo_hello foo_world baz_experiment_percentage bar_baz] end - subject(:cop) { described_class.new } - before do allow(cop).to receive(:defined_feature_flags).and_return(defined_feature_flags) allow(cop).to receive(:usage_data_counters_known_event_feature_flags).and_return([]) diff --git a/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb b/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb index bf8409534f7..9f1691696eb 100644 --- a/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb +++ b/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb @@ -6,8 +6,6 @@ require_relative '../../../../rubocop/cop/gitlab/module_with_instance_variables' RSpec.describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do let(:msg) { "Do not use instance variables in a module. [...]" } - subject(:cop) { described_class.new } - shared_examples('registering offense') do it 'registers an offense when instance variable is used in a module' do expect_offense(source) diff --git a/spec/rubocop/cop/gitlab/namespaced_class_spec.rb b/spec/rubocop/cop/gitlab/namespaced_class_spec.rb index f868a259f81..b16c3aba5c7 100644 --- a/spec/rubocop/cop/gitlab/namespaced_class_spec.rb +++ b/spec/rubocop/cop/gitlab/namespaced_class_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/namespaced_class' RSpec.describe RuboCop::Cop::Gitlab::NamespacedClass do - subject(:cop) { described_class.new } - shared_examples 'enforces namespaced classes' do def namespaced(code) return code unless namespace diff --git a/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb b/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb index ae50a1fa676..d00a9861c77 100644 --- a/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb +++ b/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/policy_rule_boolean' RSpec.describe RuboCop::Cop::Gitlab::PolicyRuleBoolean do - subject(:cop) { described_class.new } - it 'registers offense for &&' do expect_offense(<<~SOURCE) rule { conducts_electricity && batteries }.enable :light_bulb diff --git a/spec/rubocop/cop/gitlab/predicate_memoization_spec.rb b/spec/rubocop/cop/gitlab/predicate_memoization_spec.rb index 40c2c30284f..1ca34ad90da 100644 --- a/spec/rubocop/cop/gitlab/predicate_memoization_spec.rb +++ b/spec/rubocop/cop/gitlab/predicate_memoization_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/predicate_memoization' RSpec.describe RuboCop::Cop::Gitlab::PredicateMemoization do - subject(:cop) { described_class.new } - shared_examples('not registering offense') do it 'does not register offenses' do expect_no_offenses(source) diff --git a/spec/rubocop/cop/gitlab/rails_logger_spec.rb b/spec/rubocop/cop/gitlab/rails_logger_spec.rb index ab47406d055..c9d361b49b8 100644 --- a/spec/rubocop/cop/gitlab/rails_logger_spec.rb +++ b/spec/rubocop/cop/gitlab/rails_logger_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/rails_logger' RSpec.describe RuboCop::Cop::Gitlab::RailsLogger do - subject(:cop) { described_class.new } - described_class::LOG_METHODS.each do |method| it "flags the use of Rails.logger.#{method} with a constant receiver" do node = "Rails.logger.#{method}('some error')" diff --git a/spec/rubocop/cop/gitlab/union_spec.rb b/spec/rubocop/cop/gitlab/union_spec.rb index d8080e8298b..4042fe0263a 100644 --- a/spec/rubocop/cop/gitlab/union_spec.rb +++ b/spec/rubocop/cop/gitlab/union_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/gitlab/union' RSpec.describe RuboCop::Cop::Gitlab::Union do - subject(:cop) { described_class.new } - it 'flags the use of Gitlab::SQL::Union.new' do expect_offense(<<~SOURCE) Gitlab::SQL::Union.new([foo]) diff --git a/spec/rubocop/cop/graphql/authorize_types_spec.rb b/spec/rubocop/cop/graphql/authorize_types_spec.rb index 3ea4d3e4a4d..a30cd5a1688 100644 --- a/spec/rubocop/cop/graphql/authorize_types_spec.rb +++ b/spec/rubocop/cop/graphql/authorize_types_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/graphql/authorize_types' RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes do - subject(:cop) { described_class.new } - it 'adds an offense when there is no authorize call' do expect_offense(<<~TYPE) module Types diff --git a/spec/rubocop/cop/graphql/descriptions_spec.rb b/spec/rubocop/cop/graphql/descriptions_spec.rb index f4fd78c846d..8826e700fdf 100644 --- a/spec/rubocop/cop/graphql/descriptions_spec.rb +++ b/spec/rubocop/cop/graphql/descriptions_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/graphql/descriptions' RSpec.describe RuboCop::Cop::Graphql::Descriptions do - subject(:cop) { described_class.new } - context 'with fields' do it 'adds an offense when there is no description' do expect_offense(<<~TYPE) diff --git a/spec/rubocop/cop/graphql/gid_expected_type_spec.rb b/spec/rubocop/cop/graphql/gid_expected_type_spec.rb index c6cd3ba0913..563c16a99df 100644 --- a/spec/rubocop/cop/graphql/gid_expected_type_spec.rb +++ b/spec/rubocop/cop/graphql/gid_expected_type_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/graphql/gid_expected_type' RSpec.describe RuboCop::Cop::Graphql::GIDExpectedType do - subject(:cop) { described_class.new } - it 'adds an offense when there is no expected_type parameter' do expect_offense(<<~TYPE) GitlabSchema.object_from_id(received_id) diff --git a/spec/rubocop/cop/graphql/graphql_name_position_spec.rb b/spec/rubocop/cop/graphql/graphql_name_position_spec.rb index 7bbbbed6e05..5db6fe6a801 100644 --- a/spec/rubocop/cop/graphql/graphql_name_position_spec.rb +++ b/spec/rubocop/cop/graphql/graphql_name_position_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/graphql/graphql_name_position' RSpec.describe RuboCop::Cop::Graphql::GraphqlNamePosition do - subject(:cop) { described_class.new } - it 'adds an offense when graphql_name is not on the first line' do expect_offense(<<~TYPE) module Types diff --git a/spec/rubocop/cop/graphql/id_type_spec.rb b/spec/rubocop/cop/graphql/id_type_spec.rb index fcd64561fe4..3a56753d39e 100644 --- a/spec/rubocop/cop/graphql/id_type_spec.rb +++ b/spec/rubocop/cop/graphql/id_type_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/graphql/id_type' RSpec.describe RuboCop::Cop::Graphql::IDType do - subject(:cop) { described_class.new } - it 'adds an offense when GraphQL::Types::ID is used as a param to #argument' do expect_offense(<<~TYPE) argument :some_arg, GraphQL::Types::ID, some: other, params: do_not_matter diff --git a/spec/rubocop/cop/graphql/json_type_spec.rb b/spec/rubocop/cop/graphql/json_type_spec.rb index d048fc4178b..c72e5b5b1c9 100644 --- a/spec/rubocop/cop/graphql/json_type_spec.rb +++ b/spec/rubocop/cop/graphql/json_type_spec.rb @@ -8,8 +8,6 @@ RSpec.describe RuboCop::Cop::Graphql::JSONType do 'Avoid using GraphQL::Types::JSON. See: https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#json' end - subject(:cop) { described_class.new } - context 'fields' do it 'adds an offense when GraphQL::Types::JSON is used' do expect_offense(<<~RUBY) diff --git a/spec/rubocop/cop/graphql/old_types_spec.rb b/spec/rubocop/cop/graphql/old_types_spec.rb index cb3d0087cbe..45d47f3b516 100644 --- a/spec/rubocop/cop/graphql/old_types_spec.rb +++ b/spec/rubocop/cop/graphql/old_types_spec.rb @@ -7,8 +7,6 @@ require_relative '../../../../rubocop/cop/graphql/old_types' RSpec.describe RuboCop::Cop::Graphql::OldTypes do using RSpec::Parameterized::TableSyntax - subject(:cop) { described_class.new } - where(:old_type, :message) do 'GraphQL::ID_TYPE' | 'Avoid using GraphQL::ID_TYPE. Use GraphQL::Types::ID instead' 'GraphQL::INT_TYPE' | 'Avoid using GraphQL::INT_TYPE. Use GraphQL::Types::Int instead' diff --git a/spec/rubocop/cop/graphql/resolver_type_spec.rb b/spec/rubocop/cop/graphql/resolver_type_spec.rb index 7b5213fdb3d..ade1bfc2cca 100644 --- a/spec/rubocop/cop/graphql/resolver_type_spec.rb +++ b/spec/rubocop/cop/graphql/resolver_type_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/graphql/resolver_type' RSpec.describe RuboCop::Cop::Graphql::ResolverType do - subject(:cop) { described_class.new } - it 'adds an offense when there is no type annotation' do expect_offense(<<~SRC) module Resolvers diff --git a/spec/rubocop/cop/group_public_or_visible_to_user_spec.rb b/spec/rubocop/cop/group_public_or_visible_to_user_spec.rb index b51c3d94aaa..c948ea606b8 100644 --- a/spec/rubocop/cop/group_public_or_visible_to_user_spec.rb +++ b/spec/rubocop/cop/group_public_or_visible_to_user_spec.rb @@ -9,8 +9,6 @@ RSpec.describe RuboCop::Cop::GroupPublicOrVisibleToUser do "Please ensure that you are not using it on its own and that the amount of rows being filtered is reasonable." end - subject(:cop) { described_class.new } - it 'flags the use of Group.public_or_visible_to_user with a constant receiver' do expect_offense(<<~CODE) Group.public_or_visible_to_user diff --git a/spec/rubocop/cop/ignored_columns_spec.rb b/spec/rubocop/cop/ignored_columns_spec.rb index 7c4f9c13856..c6c44399624 100644 --- a/spec/rubocop/cop/ignored_columns_spec.rb +++ b/spec/rubocop/cop/ignored_columns_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/ignored_columns' RSpec.describe RuboCop::Cop::IgnoredColumns do - subject(:cop) { described_class.new } - it 'flags direct use of ignored_columns instead of the IgnoredColumns concern' do expect_offense(<<~RUBY) class Foo < ApplicationRecord diff --git a/spec/rubocop/cop/include_sidekiq_worker_spec.rb b/spec/rubocop/cop/include_sidekiq_worker_spec.rb index bbb5232a1b4..f86bb1427db 100644 --- a/spec/rubocop/cop/include_sidekiq_worker_spec.rb +++ b/spec/rubocop/cop/include_sidekiq_worker_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/include_sidekiq_worker' RSpec.describe RuboCop::Cop::IncludeSidekiqWorker do - subject(:cop) { described_class.new } - context 'when `Sidekiq::Worker` is included' do it 'registers an offense and corrects', :aggregate_failures do expect_offense(<<~CODE) diff --git a/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb b/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb index 91ef2532e99..3063a474bd7 100644 --- a/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb +++ b/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/inject_enterprise_edition_module' RSpec.describe RuboCop::Cop::InjectEnterpriseEditionModule do - subject(:cop) { described_class.new } - it 'flags the use of `prepend_mod_with` in the middle of a file' do expect_offense(<<~SOURCE) class Foo diff --git a/spec/rubocop/cop/lint/last_keyword_argument_spec.rb b/spec/rubocop/cop/lint/last_keyword_argument_spec.rb index c2f3706cdb1..b0551a79c50 100644 --- a/spec/rubocop/cop/lint/last_keyword_argument_spec.rb +++ b/spec/rubocop/cop/lint/last_keyword_argument_spec.rb @@ -4,16 +4,15 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/lint/last_keyword_argument' RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument do - subject(:cop) { described_class.new } - before do described_class.instance_variable_set(:@keyword_warnings, nil) + allow(Dir).to receive(:glob).and_call_original + allow(File).to receive(:read).and_call_original end context 'deprecation files does not exist' do before do - allow(Dir).to receive(:glob).and_return([]) - allow(File).to receive(:exist?).and_return(false) + allow(Dir).to receive(:glob).with(described_class::DEPRECATIONS_GLOB).and_return([]) end it 'does not register an offense' do @@ -58,7 +57,8 @@ RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument do before do allow(Dir).to receive(:glob).and_return(['deprecations/service/create_spec.yml', 'deprecations/api/projects_spec.yml']) - allow(File).to receive(:read).and_return(create_spec_yaml, projects_spec_yaml) + allow(File).to receive(:read).with('deprecations/service/create_spec.yml').and_return(create_spec_yaml) + allow(File).to receive(:read).with('deprecations/api/projects_spec.yml').and_return(projects_spec_yaml) end it 'registers an offense for last keyword warning' do diff --git a/spec/rubocop/cop/migration/add_concurrent_index_spec.rb b/spec/rubocop/cop/migration/add_concurrent_index_spec.rb index 6344cbb3b5a..185b64b0334 100644 --- a/spec/rubocop/cop/migration/add_concurrent_index_spec.rb +++ b/spec/rubocop/cop/migration/add_concurrent_index_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/add_concurrent_index' RSpec.describe RuboCop::Cop::Migration::AddConcurrentIndex do - subject(:cop) { described_class.new } - context 'when in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) diff --git a/spec/rubocop/cop/migration/add_index_spec.rb b/spec/rubocop/cop/migration/add_index_spec.rb index 595cb31e14e..338dbf73a3a 100644 --- a/spec/rubocop/cop/migration/add_index_spec.rb +++ b/spec/rubocop/cop/migration/add_index_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/add_index' RSpec.describe RuboCop::Cop::Migration::AddIndex do - subject(:cop) { described_class.new } - context 'in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) 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 78db7938fa3..85a86a27c48 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 @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/add_limit_to_text_columns' RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns do - subject(:cop) { described_class.new } - context 'when in migration' do let(:msg) { 'Text columns should always have a limit set (255 is suggested)[...]' } diff --git a/spec/rubocop/cop/migration/add_timestamps_spec.rb b/spec/rubocop/cop/migration/add_timestamps_spec.rb index 593a0b00f07..fcc2f4aa363 100644 --- a/spec/rubocop/cop/migration/add_timestamps_spec.rb +++ b/spec/rubocop/cop/migration/add_timestamps_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/add_timestamps' RSpec.describe RuboCop::Cop::Migration::AddTimestamps do - subject(:cop) { described_class.new } - let(:migration_with_add_timestamps) do %q( class Users < ActiveRecord::Migration[4.2] diff --git a/spec/rubocop/cop/migration/background_migration_base_class_spec.rb b/spec/rubocop/cop/migration/background_migration_base_class_spec.rb index 140820e84bd..8cc85ac692c 100644 --- a/spec/rubocop/cop/migration/background_migration_base_class_spec.rb +++ b/spec/rubocop/cop/migration/background_migration_base_class_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/background_migration_base_class' RSpec.describe RuboCop::Cop::Migration::BackgroundMigrationBaseClass do - subject(:cop) { described_class.new } - context 'when the migration class inherits from BatchedMigrationJob' do it 'does not register any offenses' do expect_no_offenses(<<~RUBY) diff --git a/spec/rubocop/cop/migration/background_migration_record_spec.rb b/spec/rubocop/cop/migration/background_migration_record_spec.rb index 9e482293b93..d5a451e00c9 100644 --- a/spec/rubocop/cop/migration/background_migration_record_spec.rb +++ b/spec/rubocop/cop/migration/background_migration_record_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/background_migration_record' RSpec.describe RuboCop::Cop::Migration::BackgroundMigrationRecord do - subject(:cop) { described_class.new } - context 'outside of a migration' do it 'does not register any offenses' do expect_no_offenses(<<~SOURCE) diff --git a/spec/rubocop/cop/migration/complex_indexes_require_name_spec.rb b/spec/rubocop/cop/migration/complex_indexes_require_name_spec.rb index 4ffe9b17011..7329d399330 100644 --- a/spec/rubocop/cop/migration/complex_indexes_require_name_spec.rb +++ b/spec/rubocop/cop/migration/complex_indexes_require_name_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/complex_indexes_require_name' RSpec.describe RuboCop::Cop::Migration::ComplexIndexesRequireName do - subject(:cop) { described_class.new } - context 'when in migration' do let(:msg) { 'indexes added with custom options must be explicitly named' } diff --git a/spec/rubocop/cop/migration/datetime_spec.rb b/spec/rubocop/cop/migration/datetime_spec.rb index b8ec8674b56..400abe3be70 100644 --- a/spec/rubocop/cop/migration/datetime_spec.rb +++ b/spec/rubocop/cop/migration/datetime_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/datetime' RSpec.describe RuboCop::Cop::Migration::Datetime do - subject(:cop) { described_class.new } - let(:create_table_migration_without_datetime) do %q( class Users < ActiveRecord::Migration[6.0] diff --git a/spec/rubocop/cop/migration/drop_table_spec.rb b/spec/rubocop/cop/migration/drop_table_spec.rb index d172b0c5bb0..dd5f93eaafc 100644 --- a/spec/rubocop/cop/migration/drop_table_spec.rb +++ b/spec/rubocop/cop/migration/drop_table_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/drop_table' RSpec.describe RuboCop::Cop::Migration::DropTable do - subject(:cop) { described_class.new } - context 'when in deployment migration' do let(:msg) do '`drop_table` in deployment migrations requires downtime. Drop tables in post-deployment migrations instead.' diff --git a/spec/rubocop/cop/migration/migration_record_spec.rb b/spec/rubocop/cop/migration/migration_record_spec.rb index e941b8f8a87..96a1d8fa107 100644 --- a/spec/rubocop/cop/migration/migration_record_spec.rb +++ b/spec/rubocop/cop/migration/migration_record_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/migration_record' RSpec.describe RuboCop::Cop::Migration::MigrationRecord do - subject(:cop) { described_class.new } - shared_examples 'a disabled cop' do |klass| it 'does not register any offenses' do expect_no_offenses(<<~SOURCE) diff --git a/spec/rubocop/cop/migration/prevent_global_enable_lock_retries_with_disable_ddl_transaction_spec.rb b/spec/rubocop/cop/migration/prevent_global_enable_lock_retries_with_disable_ddl_transaction_spec.rb index 7afecfd39b2..1035ed2fb4a 100644 --- a/spec/rubocop/cop/migration/prevent_global_enable_lock_retries_with_disable_ddl_transaction_spec.rb +++ b/spec/rubocop/cop/migration/prevent_global_enable_lock_retries_with_disable_ddl_transaction_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/prevent_global_enable_lock_retries_with_disable_ddl_transaction' RSpec.describe RuboCop::Cop::Migration::PreventGlobalEnableLockRetriesWithDisableDdlTransaction do - subject(:cop) { described_class.new } - context 'when in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) diff --git a/spec/rubocop/cop/migration/prevent_index_creation_spec.rb b/spec/rubocop/cop/migration/prevent_index_creation_spec.rb index 54393e69cf2..9d886467a48 100644 --- a/spec/rubocop/cop/migration/prevent_index_creation_spec.rb +++ b/spec/rubocop/cop/migration/prevent_index_creation_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/prevent_index_creation' RSpec.describe RuboCop::Cop::Migration::PreventIndexCreation do - subject(:cop) { described_class.new } - let(:forbidden_tables) { %w(ci_builds) } let(:forbidden_tables_list) { forbidden_tables.join(', ') } diff --git a/spec/rubocop/cop/migration/prevent_strings_spec.rb b/spec/rubocop/cop/migration/prevent_strings_spec.rb index 6f5d1ca4368..f1adeae6786 100644 --- a/spec/rubocop/cop/migration/prevent_strings_spec.rb +++ b/spec/rubocop/cop/migration/prevent_strings_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/prevent_strings' RSpec.describe RuboCop::Cop::Migration::PreventStrings do - subject(:cop) { described_class.new } - context 'when in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) diff --git a/spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb b/spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb index 18d5353ce46..acdc6843584 100644 --- a/spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb +++ b/spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/refer_to_index_by_name' RSpec.describe RuboCop::Cop::Migration::ReferToIndexByName do - subject(:cop) { described_class.new } - context 'when in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) diff --git a/spec/rubocop/cop/migration/remove_column_spec.rb b/spec/rubocop/cop/migration/remove_column_spec.rb index 89edb3b420e..4aa842969fe 100644 --- a/spec/rubocop/cop/migration/remove_column_spec.rb +++ b/spec/rubocop/cop/migration/remove_column_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/remove_column' RSpec.describe RuboCop::Cop::Migration::RemoveColumn do - subject(:cop) { described_class.new } - def source(meth = 'change') "def #{meth}; remove_column :table, :column; end" end diff --git a/spec/rubocop/cop/migration/remove_concurrent_index_spec.rb b/spec/rubocop/cop/migration/remove_concurrent_index_spec.rb index 86bd3a2edea..1d59390d659 100644 --- a/spec/rubocop/cop/migration/remove_concurrent_index_spec.rb +++ b/spec/rubocop/cop/migration/remove_concurrent_index_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/remove_concurrent_index' RSpec.describe RuboCop::Cop::Migration::RemoveConcurrentIndex do - subject(:cop) { described_class.new } - context 'in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) diff --git a/spec/rubocop/cop/migration/remove_index_spec.rb b/spec/rubocop/cop/migration/remove_index_spec.rb index bc8571b7e4d..24823b47d53 100644 --- a/spec/rubocop/cop/migration/remove_index_spec.rb +++ b/spec/rubocop/cop/migration/remove_index_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/remove_index' RSpec.describe RuboCop::Cop::Migration::RemoveIndex do - subject(:cop) { described_class.new } - context 'when in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) diff --git a/spec/rubocop/cop/migration/safer_boolean_column_spec.rb b/spec/rubocop/cop/migration/safer_boolean_column_spec.rb index ef9bfb20cc8..2050051cac7 100644 --- a/spec/rubocop/cop/migration/safer_boolean_column_spec.rb +++ b/spec/rubocop/cop/migration/safer_boolean_column_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/safer_boolean_column' RSpec.describe RuboCop::Cop::Migration::SaferBooleanColumn do - subject(:cop) { described_class.new } - context 'in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) diff --git a/spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb b/spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb index 7f451fb7b28..46c460b5d49 100644 --- a/spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb +++ b/spec/rubocop/cop/migration/sidekiq_queue_migrate_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/sidekiq_queue_migrate' RSpec.describe RuboCop::Cop::Migration::SidekiqQueueMigrate do - subject(:cop) { described_class.new } - def source(meth = 'change') "def #{meth}; sidekiq_queue_migrate 'queue', to: 'new_queue'; end" end diff --git a/spec/rubocop/cop/migration/timestamps_spec.rb b/spec/rubocop/cop/migration/timestamps_spec.rb index 5508e0f564e..706fd8a3d0f 100644 --- a/spec/rubocop/cop/migration/timestamps_spec.rb +++ b/spec/rubocop/cop/migration/timestamps_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/timestamps' RSpec.describe RuboCop::Cop::Migration::Timestamps do - subject(:cop) { described_class.new } - let(:migration_with_timestamps) do %q( class Users < ActiveRecord::Migration[4.2] diff --git a/spec/rubocop/cop/migration/versioned_migration_class_spec.rb b/spec/rubocop/cop/migration/versioned_migration_class_spec.rb index 0ede5439069..b44f5d64a62 100644 --- a/spec/rubocop/cop/migration/versioned_migration_class_spec.rb +++ b/spec/rubocop/cop/migration/versioned_migration_class_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/versioned_migration_class' RSpec.describe RuboCop::Cop::Migration::VersionedMigrationClass do - subject(:cop) { described_class.new } - let(:migration) do <<~SOURCE class TestMigration < Gitlab::Database::Migration[1.0] diff --git a/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb b/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb index 67e45ac06e0..5762f78820c 100644 --- a/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb +++ b/spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/with_lock_retries_disallowed_method' RSpec.describe RuboCop::Cop::Migration::WithLockRetriesDisallowedMethod do - subject(:cop) { described_class.new } - context 'when in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) diff --git a/spec/rubocop/cop/migration/with_lock_retries_with_change_spec.rb b/spec/rubocop/cop/migration/with_lock_retries_with_change_spec.rb index fc9f8a14e3f..fed9176ea97 100644 --- a/spec/rubocop/cop/migration/with_lock_retries_with_change_spec.rb +++ b/spec/rubocop/cop/migration/with_lock_retries_with_change_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/migration/with_lock_retries_with_change' RSpec.describe RuboCop::Cop::Migration::WithLockRetriesWithChange do - subject(:cop) { described_class.new } - context 'when in migration' do before do allow(cop).to receive(:in_migration?).and_return(true) diff --git a/spec/rubocop/cop/performance/active_record_subtransaction_methods_spec.rb b/spec/rubocop/cop/performance/active_record_subtransaction_methods_spec.rb index 1394dfe7f18..ac58ca1edf3 100644 --- a/spec/rubocop/cop/performance/active_record_subtransaction_methods_spec.rb +++ b/spec/rubocop/cop/performance/active_record_subtransaction_methods_spec.rb @@ -6,8 +6,6 @@ require 'rspec-parameterized' require_relative '../../../../rubocop/cop/performance/active_record_subtransaction_methods' RSpec.describe RuboCop::Cop::Performance::ActiveRecordSubtransactionMethods do - subject(:cop) { described_class.new } - let(:message) { described_class::MSG } shared_examples 'a method that uses a subtransaction' do |method_name| diff --git a/spec/rubocop/cop/performance/active_record_subtransactions_spec.rb b/spec/rubocop/cop/performance/active_record_subtransactions_spec.rb index 55889654272..e839a3e9367 100644 --- a/spec/rubocop/cop/performance/active_record_subtransactions_spec.rb +++ b/spec/rubocop/cop/performance/active_record_subtransactions_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/performance/active_record_subtransactions' RSpec.describe RuboCop::Cop::Performance::ActiveRecordSubtransactions do - subject(:cop) { described_class.new } - let(:message) { described_class::MSG } context 'when calling #transaction with only requires_new: true' do diff --git a/spec/rubocop/cop/performance/ar_count_each_spec.rb b/spec/rubocop/cop/performance/ar_count_each_spec.rb index e37a306efbb..a86b3f2b983 100644 --- a/spec/rubocop/cop/performance/ar_count_each_spec.rb +++ b/spec/rubocop/cop/performance/ar_count_each_spec.rb @@ -4,11 +4,9 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/performance/ar_count_each' RSpec.describe RuboCop::Cop::Performance::ARCountEach do - subject(:cop) { described_class.new } - context 'when it is not haml file' do it 'does not flag it as an offense' do - expect(subject).to receive(:in_haml_file?).with(anything).at_least(:once).and_return(false) + expect(cop).to receive(:in_haml_file?).with(anything).at_least(:once).and_return(false) expect_no_offenses <<~SOURCE show(@users.count) @@ -19,7 +17,7 @@ RSpec.describe RuboCop::Cop::Performance::ARCountEach do context 'when it is haml file' do before do - expect(subject).to receive(:in_haml_file?).with(anything).at_least(:once).and_return(true) + expect(cop).to receive(:in_haml_file?).with(anything).at_least(:once).and_return(true) end context 'when the same object uses count and each' do diff --git a/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb b/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb index 4a2e62623a4..070e792eeec 100644 --- a/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb +++ b/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb @@ -4,11 +4,9 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/performance/ar_exists_and_present_blank' RSpec.describe RuboCop::Cop::Performance::ARExistsAndPresentBlank do - subject(:cop) { described_class.new } - context 'when it is not haml file' do it 'does not flag it as an offense' do - expect(subject).to receive(:in_haml_file?).with(anything).at_least(:once).and_return(false) + expect(cop).to receive(:in_haml_file?).with(anything).at_least(:once).and_return(false) expect_no_offenses <<~SOURCE return unless @users.exists? @@ -19,7 +17,7 @@ RSpec.describe RuboCop::Cop::Performance::ARExistsAndPresentBlank do context 'when it is haml file' do before do - expect(subject).to receive(:in_haml_file?).with(anything).at_least(:once).and_return(true) + expect(cop).to receive(:in_haml_file?).with(anything).at_least(:once).and_return(true) end context 'the same object uses exists? and present?' do diff --git a/spec/rubocop/cop/performance/readlines_each_spec.rb b/spec/rubocop/cop/performance/readlines_each_spec.rb index 16421bcdaac..d876cbf79a5 100644 --- a/spec/rubocop/cop/performance/readlines_each_spec.rb +++ b/spec/rubocop/cop/performance/readlines_each_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/performance/readlines_each' RSpec.describe RuboCop::Cop::Performance::ReadlinesEach do - subject(:cop) { described_class.new } - let(:message) { 'Avoid `IO.readlines.each`, since it reads contents into memory in full. Use `IO.each_line` or `IO.each` instead.' } shared_examples_for(:class_read) do |klass| diff --git a/spec/rubocop/cop/prefer_class_methods_over_module_spec.rb b/spec/rubocop/cop/prefer_class_methods_over_module_spec.rb index 455d08951bd..a2a4270c48e 100644 --- a/spec/rubocop/cop/prefer_class_methods_over_module_spec.rb +++ b/spec/rubocop/cop/prefer_class_methods_over_module_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/prefer_class_methods_over_module' RSpec.describe RuboCop::Cop::PreferClassMethodsOverModule do - subject(:cop) { described_class.new } - it 'flags violation when using module ClassMethods and corrects', :aggregate_failures do expect_offense(<<~RUBY) module Foo diff --git a/spec/rubocop/cop/project_path_helper_spec.rb b/spec/rubocop/cop/project_path_helper_spec.rb index d8e66489e3c..3153c928c77 100644 --- a/spec/rubocop/cop/project_path_helper_spec.rb +++ b/spec/rubocop/cop/project_path_helper_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/project_path_helper' RSpec.describe RuboCop::Cop::ProjectPathHelper do - subject(:cop) { described_class.new } - context "when using namespace_project with the project's namespace" do let(:source) { 'edit_namespace_project_issue_path(@issue.project.namespace, @issue.project, @issue)' } let(:correct_source) { 'edit_project_issue_path(@issue.project, @issue)' } diff --git a/spec/rubocop/cop/put_group_routes_under_scope_spec.rb b/spec/rubocop/cop/put_group_routes_under_scope_spec.rb index a68cb30ac91..8697345cddc 100644 --- a/spec/rubocop/cop/put_group_routes_under_scope_spec.rb +++ b/spec/rubocop/cop/put_group_routes_under_scope_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/put_group_routes_under_scope' RSpec.describe RuboCop::Cop::PutGroupRoutesUnderScope do - subject(:cop) { described_class.new } - %w[resource resources get post put patch delete].each do |route_method| it "registers an offense when route is outside scope for `#{route_method}`" do offense = "#{route_method} :notes" diff --git a/spec/rubocop/cop/put_project_routes_under_scope_spec.rb b/spec/rubocop/cop/put_project_routes_under_scope_spec.rb index 82cafbeb73c..65d330b0f05 100644 --- a/spec/rubocop/cop/put_project_routes_under_scope_spec.rb +++ b/spec/rubocop/cop/put_project_routes_under_scope_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/put_project_routes_under_scope' RSpec.describe RuboCop::Cop::PutProjectRoutesUnderScope do - subject(:cop) { described_class.new } - %w[resource resources get post put patch delete].each do |route_method| it "registers an offense when route is outside scope for `#{route_method}`" do offense = "#{route_method} :notes" diff --git a/spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb b/spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb index dd03c531b36..ab270090c7d 100644 --- a/spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb +++ b/spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb @@ -7,8 +7,6 @@ require_relative '../../../../rubocop/cop/qa/ambiguous_page_object_name' RSpec.describe RuboCop::Cop::QA::AmbiguousPageObjectName do let(:source_file) { 'qa/page.rb' } - subject(:cop) { described_class.new } - context 'in a QA file' do before do allow(cop).to receive(:in_qa_file?).and_return(true) diff --git a/spec/rubocop/cop/qa/element_with_pattern_spec.rb b/spec/rubocop/cop/qa/element_with_pattern_spec.rb index eb098e8f288..1febdaf9c3b 100644 --- a/spec/rubocop/cop/qa/element_with_pattern_spec.rb +++ b/spec/rubocop/cop/qa/element_with_pattern_spec.rb @@ -7,8 +7,6 @@ require_relative '../../../../rubocop/cop/qa/element_with_pattern' RSpec.describe RuboCop::Cop::QA::ElementWithPattern do let(:source_file) { 'qa/page.rb' } - subject(:cop) { described_class.new } - context 'in a QA file' do before do allow(cop).to receive(:in_qa_file?).and_return(true) diff --git a/spec/rubocop/cop/qa/selector_usage_spec.rb b/spec/rubocop/cop/qa/selector_usage_spec.rb index 4045c82a5d8..0ec289c1da6 100644 --- a/spec/rubocop/cop/qa/selector_usage_spec.rb +++ b/spec/rubocop/cop/qa/selector_usage_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/qa/selector_usage' RSpec.describe RuboCop::Cop::QA::SelectorUsage do - subject(:cop) { described_class.new } - shared_examples 'non-qa file usage' do it 'reports an offense' do expect_offense(<<-RUBY) diff --git a/spec/rubocop/cop/rspec/any_instance_of_spec.rb b/spec/rubocop/cop/rspec/any_instance_of_spec.rb index 948664c110a..f9675e17842 100644 --- a/spec/rubocop/cop/rspec/any_instance_of_spec.rb +++ b/spec/rubocop/cop/rspec/any_instance_of_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/rspec/any_instance_of' RSpec.describe RuboCop::Cop::RSpec::AnyInstanceOf do - subject(:cop) { described_class.new } - context 'when calling allow_any_instance_of' do let(:source) do <<~SRC diff --git a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb index 02eefe23df5..c26fa32db8e 100644 --- a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb +++ b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb @@ -6,8 +6,6 @@ require_relative '../../../../rubocop/cop/rspec/be_success_matcher' RSpec.describe RuboCop::Cop::RSpec::BeSuccessMatcher do let(:source_file) { 'spec/foo_spec.rb' } - subject(:cop) { described_class.new } - shared_examples 'cop' do |good:, bad:| context "using #{bad} call" do it 'registers an offense and corrects', :aggregate_failures do diff --git a/spec/rubocop/cop/rspec/env_assignment_spec.rb b/spec/rubocop/cop/rspec/env_assignment_spec.rb index 10559a30271..6212cda0b88 100644 --- a/spec/rubocop/cop/rspec/env_assignment_spec.rb +++ b/spec/rubocop/cop/rspec/env_assignment_spec.rb @@ -10,8 +10,6 @@ RSpec.describe RuboCop::Cop::RSpec::EnvAssignment do let(:source_file) { 'spec/foo_spec.rb' } - subject(:cop) { described_class.new } - shared_examples 'an offensive and correction ENV#[]= call' do |content, autocorrected_content| it "registers an offense for `#{content}` and corrects", :aggregate_failures do expect_offense(<<~CODE) diff --git a/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb b/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb index ad044b29a97..a07cf472ef0 100644 --- a/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb +++ b/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb @@ -6,8 +6,6 @@ require_relative '../../../../rubocop/cop/rspec/expect_gitlab_tracking' RSpec.describe RuboCop::Cop::RSpec::ExpectGitlabTracking do let(:source_file) { 'spec/foo_spec.rb' } - subject(:cop) { described_class.new } - good_samples = [ 'expect_snowplow_event(category: nil, action: nil)', 'expect_snowplow_event(category: "EventCategory", action: "event_action")', diff --git a/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb b/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb index 14fd5de45df..e41dd338387 100644 --- a/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb +++ b/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/rspec/factories_in_migration_specs' RSpec.describe RuboCop::Cop::RSpec::FactoriesInMigrationSpecs do - subject(:cop) { described_class.new } - shared_examples 'an offensive factory call' do |namespace| %i[build build_list create create_list attributes_for].each do |forbidden_method| namespaced_forbidden_method = "#{namespace}#{forbidden_method}(:user)" diff --git a/spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb b/spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb index 260c622498f..008af734a99 100644 --- a/spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb +++ b/spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb @@ -6,8 +6,6 @@ require 'rspec-parameterized' require_relative '../../../../../rubocop/cop/rspec/factory_bot/inline_association' RSpec.describe RuboCop::Cop::RSpec::FactoryBot::InlineAssociation do - subject(:cop) { described_class.new } - shared_examples 'offense' do |code_snippet, autocorrected| # We allow `create` or `FactoryBot.create` or `::FactoryBot.create` let(:type) { code_snippet[/^(?:::)?(?:FactoryBot\.)?(\w+)/, 1] } diff --git a/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb b/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb index 356fe20556d..e8a60b9cad7 100644 --- a/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb +++ b/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb @@ -10,8 +10,6 @@ RSpec.describe RuboCop::Cop::RSpec::HaveGitlabHttpStatus do let(:source_file) { 'spec/foo_spec.rb' } - subject(:cop) { described_class.new } - shared_examples 'offense' do |bad, good| it 'registers an offense', :aggregate_failures do expect_offense(<<~CODE, node: bad) diff --git a/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb b/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb index 8dc68e877ce..537a7a9a7e9 100644 --- a/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb +++ b/spec/rubocop/cop/rspec/htt_party_basic_auth_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/rspec/httparty_basic_auth' RSpec.describe RuboCop::Cop::RSpec::HTTPartyBasicAuth do - subject(:cop) { described_class.new } - 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/modify_sidekiq_middleware_spec.rb b/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb index 82aa16b72bb..3227b075758 100644 --- a/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb +++ b/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/rspec/modify_sidekiq_middleware' RSpec.describe RuboCop::Cop::RSpec::ModifySidekiqMiddleware do - subject(:cop) { described_class.new } - it 'registers an offense and corrects', :aggregate_failures do expect_offense(<<~CODE) Sidekiq::Testing.server_middleware do |chain| diff --git a/spec/rubocop/cop/rspec/timecop_freeze_spec.rb b/spec/rubocop/cop/rspec/timecop_freeze_spec.rb index 4e376a63617..4361f587da3 100644 --- a/spec/rubocop/cop/rspec/timecop_freeze_spec.rb +++ b/spec/rubocop/cop/rspec/timecop_freeze_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/rspec/timecop_freeze' RSpec.describe RuboCop::Cop::RSpec::TimecopFreeze do - subject(:cop) { described_class.new } - context 'when calling Timecop.freeze' do it 'registers an offense and corrects', :aggregate_failures do expect_offense(<<~CODE) diff --git a/spec/rubocop/cop/rspec/timecop_travel_spec.rb b/spec/rubocop/cop/rspec/timecop_travel_spec.rb index 3d048707878..89c46ff6c59 100644 --- a/spec/rubocop/cop/rspec/timecop_travel_spec.rb +++ b/spec/rubocop/cop/rspec/timecop_travel_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/rspec/timecop_travel' RSpec.describe RuboCop::Cop::RSpec::TimecopTravel do - subject(:cop) { described_class.new } - context 'when calling Timecop.travel' do it 'registers an offense and corrects', :aggregate_failures do expect_offense(<<~CODE) diff --git a/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb b/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb index 0e9a597dc11..90101e09023 100644 --- a/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb +++ b/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/rspec/top_level_describe_path' RSpec.describe RuboCop::Cop::RSpec::TopLevelDescribePath do - subject(:cop) { described_class.new } - context 'when the file ends in _spec.rb' do it 'registers no offenses' do expect_no_offenses(<<~SOURCE, 'spec/foo_spec.rb') diff --git a/spec/rubocop/cop/rspec/web_mock_enable_spec.rb b/spec/rubocop/cop/rspec/web_mock_enable_spec.rb index 1b10e7c901a..63ffc06f1ca 100644 --- a/spec/rubocop/cop/rspec/web_mock_enable_spec.rb +++ b/spec/rubocop/cop/rspec/web_mock_enable_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/rspec/web_mock_enable' RSpec.describe RuboCop::Cop::RSpec::WebMockEnable do - subject(:cop) { described_class.new } - context 'when calling WebMock.disable_net_connect!' do it 'registers an offence and autocorrects it' do expect_offense(<<~RUBY) diff --git a/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb b/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb index b960a1d093e..b687e91601c 100644 --- a/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb +++ b/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb @@ -9,8 +9,6 @@ require_relative '../../../rubocop/cop/ruby_interpolation_in_translation' RSpec.describe RuboCop::Cop::RubyInterpolationInTranslation do let(:msg) { "Don't use ruby interpolation \#{} inside translated strings, instead use %{}" } - subject(:cop) { described_class.new } - it 'does not add an offense for a regular messages' do expect_no_offenses('_("Hello world")') end diff --git a/spec/rubocop/cop/safe_params_spec.rb b/spec/rubocop/cop/safe_params_spec.rb index 135e815eb53..e6d86019d18 100644 --- a/spec/rubocop/cop/safe_params_spec.rb +++ b/spec/rubocop/cop/safe_params_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/safe_params' RSpec.describe RuboCop::Cop::SafeParams do - subject(:cop) { described_class.new } - it 'flags the params as an argument of url_for' do expect_offense(<<~SOURCE) url_for(params) diff --git a/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb b/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb index ba5b150e1f9..bd248cd028a 100644 --- a/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb +++ b/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/scalability/bulk_perform_with_context' RSpec.describe RuboCop::Cop::Scalability::BulkPerformWithContext do - subject(:cop) { described_class.new } - it "adds an offense when calling bulk_perform_async" do expect_offense(<<~CODE) Worker.bulk_perform_async(args) diff --git a/spec/rubocop/cop/scalability/cron_worker_context_spec.rb b/spec/rubocop/cop/scalability/cron_worker_context_spec.rb index bdd1406a0e6..bcf93b04d6a 100644 --- a/spec/rubocop/cop/scalability/cron_worker_context_spec.rb +++ b/spec/rubocop/cop/scalability/cron_worker_context_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/scalability/cron_worker_context' RSpec.describe RuboCop::Cop::Scalability::CronWorkerContext do - subject(:cop) { described_class.new } - it 'adds an offense when including CronjobQueue' do expect_offense(<<~CODE) class SomeWorker diff --git a/spec/rubocop/cop/scalability/file_uploads_spec.rb b/spec/rubocop/cop/scalability/file_uploads_spec.rb index c9e1e02be1a..1395615479f 100644 --- a/spec/rubocop/cop/scalability/file_uploads_spec.rb +++ b/spec/rubocop/cop/scalability/file_uploads_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/scalability/file_uploads' RSpec.describe RuboCop::Cop::Scalability::FileUploads do - subject(:cop) { described_class.new } - let(:message) { 'Do not upload files without workhorse acceleration. Please refer to https://docs.gitlab.com/ee/development/uploads.html' } context 'with required params' do diff --git a/spec/rubocop/cop/scalability/idempotent_worker_spec.rb b/spec/rubocop/cop/scalability/idempotent_worker_spec.rb index c1f841a46ec..b1984721803 100644 --- a/spec/rubocop/cop/scalability/idempotent_worker_spec.rb +++ b/spec/rubocop/cop/scalability/idempotent_worker_spec.rb @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/scalability/idempotent_worker' RSpec.describe RuboCop::Cop::Scalability::IdempotentWorker do - subject(:cop) { described_class.new } - before do allow(cop) .to receive(:in_worker?) 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 eef78397f0a..7b6578a0744 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 @@ -4,8 +4,6 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/sidekiq_load_balancing/worker_data_consistency' RSpec.describe RuboCop::Cop::SidekiqLoadBalancing::WorkerDataConsistency do - subject(:cop) { described_class.new } - before do allow(cop) .to receive(:in_worker?) diff --git a/spec/rubocop/cop/sidekiq_options_queue_spec.rb b/spec/rubocop/cop/sidekiq_options_queue_spec.rb index 8b7a67cff26..da126090a81 100644 --- a/spec/rubocop/cop/sidekiq_options_queue_spec.rb +++ b/spec/rubocop/cop/sidekiq_options_queue_spec.rb @@ -5,8 +5,6 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/sidekiq_options_queue' RSpec.describe RuboCop::Cop::SidekiqOptionsQueue do - subject(:cop) { described_class.new } - it 'registers an offense when `sidekiq_options` is used with the `queue` option' do expect_offense(<<~CODE) sidekiq_options queue: "some_queue" diff --git a/spec/rubocop/cop/static_translation_definition_spec.rb b/spec/rubocop/cop/static_translation_definition_spec.rb index 33945064b3f..10b4f162504 100644 --- a/spec/rubocop/cop/static_translation_definition_spec.rb +++ b/spec/rubocop/cop/static_translation_definition_spec.rb @@ -11,8 +11,6 @@ RSpec.describe RuboCop::Cop::StaticTranslationDefinition do let(:msg) { described_class::MSG } - subject(:cop) { described_class.new } - shared_examples 'offense' do |code| it 'registers an offense' do expect_offense(code) diff --git a/spec/rubocop/cop/usage_data/distinct_count_by_large_foreign_key_spec.rb b/spec/rubocop/cop/usage_data/distinct_count_by_large_foreign_key_spec.rb index 14b6df8de4e..b4d113a9bcc 100644 --- a/spec/rubocop/cop/usage_data/distinct_count_by_large_foreign_key_spec.rb +++ b/spec/rubocop/cop/usage_data/distinct_count_by_large_foreign_key_spec.rb @@ -13,8 +13,6 @@ RSpec.describe RuboCop::Cop::UsageData::DistinctCountByLargeForeignKey do }) end - subject(:cop) { described_class.new(config) } - context 'when counting by disallowed key' do it 'registers an offense' do expect_offense(<<~CODE) diff --git a/spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb b/spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb index df9d538d2ae..efa4e27dc9c 100644 --- a/spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb +++ b/spec/rubocop/cop/usage_data/histogram_with_large_table_spec.rb @@ -14,8 +14,6 @@ RSpec.describe RuboCop::Cop::UsageData::HistogramWithLargeTable do }) end - subject(:cop) { described_class.new(config) } - context 'with large tables' do context 'with one-level constants' do context 'when calling histogram(Issue)' do diff --git a/spec/rubocop/cop/usage_data/instrumentation_superclass_spec.rb b/spec/rubocop/cop/usage_data/instrumentation_superclass_spec.rb index 8d2427e6e69..a55f0852f35 100644 --- a/spec/rubocop/cop/usage_data/instrumentation_superclass_spec.rb +++ b/spec/rubocop/cop/usage_data/instrumentation_superclass_spec.rb @@ -14,8 +14,6 @@ RSpec.describe RuboCop::Cop::UsageData::InstrumentationSuperclass do }) end - subject(:cop) { described_class.new(config) } - context 'with class definition' do context 'when inheriting from allowed superclass' do it 'does not register an offense' do diff --git a/spec/rubocop/cop/usage_data/large_table_spec.rb b/spec/rubocop/cop/usage_data/large_table_spec.rb index befdc1caead..fa94f878cea 100644 --- a/spec/rubocop/cop/usage_data/large_table_spec.rb +++ b/spec/rubocop/cop/usage_data/large_table_spec.rb @@ -18,8 +18,6 @@ RSpec.describe RuboCop::Cop::UsageData::LargeTable do }) end - subject(:cop) { described_class.new(config) } - context 'when in usage_data files' do before do allow(cop).to receive(:usage_data_files?).and_return(true) diff --git a/spec/rubocop/cop/user_admin_spec.rb b/spec/rubocop/cop/user_admin_spec.rb index b34418adf91..99e87d619c0 100644 --- a/spec/rubocop/cop/user_admin_spec.rb +++ b/spec/rubocop/cop/user_admin_spec.rb @@ -6,8 +6,6 @@ require 'rubocop' require_relative '../../../rubocop/cop/user_admin' RSpec.describe RuboCop::Cop::UserAdmin do - subject(:cop) { described_class.new } - it 'flags a method call' do expect_offense(<<~SOURCE) user.admin? diff --git a/spec/rubocop_spec_helper.rb b/spec/rubocop_spec_helper.rb index c49437137e3..a37415a25de 100644 --- a/spec/rubocop_spec_helper.rb +++ b/spec/rubocop_spec_helper.rb @@ -14,4 +14,7 @@ RSpec.configure do |config| config.define_derived_metadata(file_path: %r{spec/rubocop}) do |metadata| metadata[:type] = :rubocop end + + # Include config shared context for all cop specs. + config.include_context 'config', type: :rubocop end diff --git a/spec/services/releases/create_service_spec.rb b/spec/services/releases/create_service_spec.rb index 2421fab0eec..5f49eed3e77 100644 --- a/spec/services/releases/create_service_spec.rb +++ b/spec/services/releases/create_service_spec.rb @@ -70,6 +70,28 @@ RSpec.describe Releases::CreateService do expect(result[:release]).not_to be_nil end + context 'and the tag would be protected' do + let!(:protected_tag) { create(:protected_tag, project: project, name: tag_name) } + + context 'and the user does not have permissions' do + let(:user) { create(:user) } + + before do + project.add_developer(user) + end + + it 'raises an error' do + result = service.execute + + expect(result[:status]).to eq(:error) + end + end + + context 'and the user has permissions' do + it_behaves_like 'a successful release creation' + end + end + context 'and tag_message is provided' do let(:ref) { 'master' } let(:tag_name) { 'foobar' } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 160f7fda543..18820eefe31 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -125,9 +125,6 @@ RSpec.configure do |config| end end - # Re-run failures locally with `--only-failures` - config.example_status_persistence_file_path = ENV.fetch('RSPEC_LAST_RUN_RESULTS_FILE', './spec/examples.txt') - config.define_derived_metadata(file_path: %r{(ee)?/spec/.+_spec\.rb\z}) do |metadata| location = metadata[:location] diff --git a/spec/support/rspec.rb b/spec/support/rspec.rb index a11b720d060..2d37501f7c6 100644 --- a/spec/support/rspec.rb +++ b/spec/support/rspec.rb @@ -11,6 +11,9 @@ require_relative "helpers/fast_rails_root" RSpec::Expectations.configuration.on_potential_false_positives = :raise RSpec.configure do |config| + # Re-run failures locally with `--only-failures` + config.example_status_persistence_file_path = ENV.fetch('RSPEC_LAST_RUN_RESULTS_FILE', './spec/examples.txt') + config.mock_with :rspec do |mocks| mocks.verify_doubled_constant_names = true end -- cgit v1.2.3