summaryrefslogtreecommitdiff
path: root/spec/rubocop
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/rubocop
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/code_reuse_helpers_spec.rb1
-rw-r--r--spec/rubocop/cop/active_record_association_reload_spec.rb1
-rw-r--r--spec/rubocop/cop/api/base_spec.rb1
-rw-r--r--spec/rubocop/cop/api/grape_array_missing_coerce_spec.rb1
-rw-r--r--spec/rubocop/cop/avoid_becomes_spec.rb1
-rw-r--r--spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb1
-rw-r--r--spec/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers_spec.rb1
-rw-r--r--spec/rubocop/cop/avoid_return_from_blocks_spec.rb13
-rw-r--r--spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb13
-rw-r--r--spec/rubocop/cop/ban_catch_throw_spec.rb1
-rw-r--r--spec/rubocop/cop/code_reuse/finder_spec.rb1
-rw-r--r--spec/rubocop/cop/code_reuse/presenter_spec.rb1
-rw-r--r--spec/rubocop/cop/code_reuse/serializer_spec.rb1
-rw-r--r--spec/rubocop/cop/code_reuse/service_class_spec.rb1
-rw-r--r--spec/rubocop/cop/code_reuse/worker_spec.rb1
-rw-r--r--spec/rubocop/cop/default_scope_spec.rb1
-rw-r--r--spec/rubocop/cop/destroy_all_spec.rb1
-rw-r--r--spec/rubocop/cop/filename_length_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/avoid_uploaded_file_from_params_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/bulk_insert_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/change_timezone_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/except_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/httparty_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/intersect_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/json_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/namespaced_class_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/predicate_memoization_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/rails_logger_spec.rb1
-rw-r--r--spec/rubocop/cop/gitlab/union_spec.rb1
-rw-r--r--spec/rubocop/cop/graphql/authorize_types_spec.rb31
-rw-r--r--spec/rubocop/cop/graphql/descriptions_spec.rb45
-rw-r--r--spec/rubocop/cop/graphql/gid_expected_type_spec.rb1
-rw-r--r--spec/rubocop/cop/graphql/id_type_spec.rb1
-rw-r--r--spec/rubocop/cop/graphql/json_type_spec.rb1
-rw-r--r--spec/rubocop/cop/graphql/resolver_type_spec.rb1
-rw-r--r--spec/rubocop/cop/group_public_or_visible_to_user_spec.rb1
-rw-r--r--spec/rubocop/cop/ignored_columns_spec.rb11
-rw-r--r--spec/rubocop/cop/include_sidekiq_worker_spec.rb1
-rw-r--r--spec/rubocop/cop/inject_enterprise_edition_module_spec.rb1
-rw-r--r--spec/rubocop/cop/lint/last_keyword_argument_spec.rb1
-rw-r--r--spec/rubocop/cop/migration/add_column_with_default_spec.rb11
-rw-r--r--spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb15
-rw-r--r--spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb31
-rw-r--r--spec/rubocop/cop/migration/add_concurrent_index_spec.rb27
-rw-r--r--spec/rubocop/cop/migration/add_index_spec.rb3
-rw-r--r--spec/rubocop/cop/migration/add_limit_to_text_columns_spec.rb41
-rw-r--r--spec/rubocop/cop/migration/add_reference_spec.rb9
-rw-r--r--spec/rubocop/cop/migration/add_timestamps_spec.rb46
-rw-r--r--spec/rubocop/cop/migration/complex_indexes_require_name_spec.rb23
-rw-r--r--spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb5
-rw-r--r--spec/rubocop/cop/migration/datetime_spec.rb149
-rw-r--r--spec/rubocop/cop/migration/drop_table_spec.rb15
-rw-r--r--spec/rubocop/cop/migration/hash_index_spec.rb47
-rw-r--r--spec/rubocop/cop/migration/prevent_strings_spec.rb23
-rw-r--r--spec/rubocop/cop/migration/refer_to_index_by_name_spec.rb21
-rw-r--r--spec/rubocop/cop/migration/remove_column_spec.rb45
-rw-r--r--spec/rubocop/cop/migration/remove_concurrent_index_spec.rb23
-rw-r--r--spec/rubocop/cop/migration/remove_index_spec.rb23
-rw-r--r--spec/rubocop/cop/migration/safer_boolean_column_spec.rb30
-rw-r--r--spec/rubocop/cop/migration/schedule_async_spec.rb97
-rw-r--r--spec/rubocop/cop/migration/timestamps_spec.rb45
-rw-r--r--spec/rubocop/cop/migration/update_column_in_batches_spec.rb35
-rw-r--r--spec/rubocop/cop/migration/with_lock_retries_disallowed_method_spec.rb68
-rw-r--r--spec/rubocop/cop/migration/with_lock_retries_with_change_spec.rb35
-rw-r--r--spec/rubocop/cop/performance/ar_count_each_spec.rb1
-rw-r--r--spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb1
-rw-r--r--spec/rubocop/cop/performance/readlines_each_spec.rb1
-rw-r--r--spec/rubocop/cop/prefer_class_methods_over_module_spec.rb43
-rw-r--r--spec/rubocop/cop/project_path_helper_spec.rb1
-rw-r--r--spec/rubocop/cop/put_group_routes_under_scope_spec.rb13
-rw-r--r--spec/rubocop/cop/put_project_routes_under_scope_spec.rb1
-rw-r--r--spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb1
-rw-r--r--spec/rubocop/cop/qa/element_with_pattern_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/be_success_matcher_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/env_assignment_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/timecop_freeze_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/timecop_travel_spec.rb1
-rw-r--r--spec/rubocop/cop/rspec/top_level_describe_path_spec.rb1
-rw-r--r--spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb1
-rw-r--r--spec/rubocop/cop/safe_params_spec.rb1
-rw-r--r--spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb1
-rw-r--r--spec/rubocop/cop/scalability/cron_worker_context_spec.rb1
-rw-r--r--spec/rubocop/cop/scalability/file_uploads_spec.rb1
-rw-r--r--spec/rubocop/cop/scalability/idempotent_worker_spec.rb1
-rw-r--r--spec/rubocop/cop/sidekiq_options_queue_spec.rb20
-rw-r--r--spec/rubocop/cop/static_translation_definition_spec.rb1
-rw-r--r--spec/rubocop/cop/usage_data/distinct_count_by_large_foreign_key_spec.rb1
-rw-r--r--spec/rubocop/cop/usage_data/large_table_spec.rb1
-rw-r--r--spec/rubocop/migration_helpers_spec.rb1
-rw-r--r--spec/rubocop/qa_helpers_spec.rb1
100 files changed, 450 insertions, 674 deletions
diff --git a/spec/rubocop/code_reuse_helpers_spec.rb b/spec/rubocop/code_reuse_helpers_spec.rb
index 4c3dd8f8167..9337df368e3 100644
--- a/spec/rubocop/code_reuse_helpers_spec.rb
+++ b/spec/rubocop/code_reuse_helpers_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require 'parser/current'
require_relative '../../rubocop/code_reuse_helpers'
diff --git a/spec/rubocop/cop/active_record_association_reload_spec.rb b/spec/rubocop/cop/active_record_association_reload_spec.rb
index f28c4e60f3c..1c0518815ee 100644
--- a/spec/rubocop/cop/active_record_association_reload_spec.rb
+++ b/spec/rubocop/cop/active_record_association_reload_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/active_record_association_reload'
RSpec.describe RuboCop::Cop::ActiveRecordAssociationReload do
diff --git a/spec/rubocop/cop/api/base_spec.rb b/spec/rubocop/cop/api/base_spec.rb
index ec646b9991b..547d3f53a08 100644
--- a/spec/rubocop/cop/api/base_spec.rb
+++ b/spec/rubocop/cop/api/base_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/api/base'
RSpec.describe RuboCop::Cop::API::Base do
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 b50866b54b3..01f1fc71f9a 100644
--- a/spec/rubocop/cop/api/grape_array_missing_coerce_spec.rb
+++ b/spec/rubocop/cop/api/grape_array_missing_coerce_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/api/grape_array_missing_coerce'
RSpec.describe RuboCop::Cop::API::GrapeArrayMissingCoerce do
diff --git a/spec/rubocop/cop/avoid_becomes_spec.rb b/spec/rubocop/cop/avoid_becomes_spec.rb
index 401c694f373..3ab1544b00d 100644
--- a/spec/rubocop/cop/avoid_becomes_spec.rb
+++ b/spec/rubocop/cop/avoid_becomes_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/avoid_becomes'
RSpec.describe RuboCop::Cop::AvoidBecomes do
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 ac59d36db3f..cc851045c3c 100644
--- a/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb
+++ b/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/avoid_break_from_strong_memoize'
RSpec.describe RuboCop::Cop::AvoidBreakFromStrongMemoize 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 460a0b13458..90ee5772b66 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
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers'
RSpec.describe RuboCop::Cop::AvoidKeywordArgumentsInSidekiqWorkers do
diff --git a/spec/rubocop/cop/avoid_return_from_blocks_spec.rb b/spec/rubocop/cop/avoid_return_from_blocks_spec.rb
index 71311b9df7f..86098f1afcc 100644
--- a/spec/rubocop/cop/avoid_return_from_blocks_spec.rb
+++ b/spec/rubocop/cop/avoid_return_from_blocks_spec.rb
@@ -1,12 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/avoid_return_from_blocks'
RSpec.describe RuboCop::Cop::AvoidReturnFromBlocks do
- include CopHelper
-
subject(:cop) { described_class.new }
it 'flags violation for return inside a block' do
@@ -19,20 +16,16 @@ RSpec.describe RuboCop::Cop::AvoidReturnFromBlocks do
RUBY
end
- it "doesn't call add_offense twice for nested blocks" do
- source = <<~RUBY
+ it "doesn't create more than one offense for nested blocks" do
+ expect_offense(<<~RUBY)
call do
call do
something
return if something_else
+ ^^^^^^ Do not return from a block, use next or break instead.
end
end
RUBY
- expect_any_instance_of(described_class) do |instance|
- expect(instance).to receive(:add_offense).once
- end
-
- inspect_source(source)
end
it 'flags violation for return inside included > def > block' 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 9e13a5278e3..61d6f45b5ba 100644
--- a/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb
+++ b/spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb
@@ -1,23 +1,24 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/avoid_route_redirect_leading_slash'
RSpec.describe RuboCop::Cop::AvoidRouteRedirectLeadingSlash do
- include CopHelper
-
subject(:cop) { described_class.new }
before do
allow(cop).to receive(:in_routes?).and_return(true)
end
- it 'registers an offense when redirect has a leading slash' do
+ it 'registers an offense when redirect has a leading slash and corrects', :aggregate_failures do
expect_offense(<<~PATTERN)
root to: redirect("/-/route")
^^^^^^^^^^^^^^^^^^^^ Do not use a leading "/" in route redirects
PATTERN
+
+ expect_correction(<<~PATTERN)
+ root to: redirect("-/route")
+ PATTERN
end
it 'does not register an offense when redirect does not have a leading slash' do
@@ -25,8 +26,4 @@ RSpec.describe RuboCop::Cop::AvoidRouteRedirectLeadingSlash do
root to: redirect("-/route")
PATTERN
end
-
- it 'autocorrect `/-/route` to `-/route`' do
- expect(autocorrect_source('redirect("/-/route")')).to eq('redirect("-/route")')
- end
end
diff --git a/spec/rubocop/cop/ban_catch_throw_spec.rb b/spec/rubocop/cop/ban_catch_throw_spec.rb
index b3c4ad8688c..f255d27e7c7 100644
--- a/spec/rubocop/cop/ban_catch_throw_spec.rb
+++ b/spec/rubocop/cop/ban_catch_throw_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/ban_catch_throw'
diff --git a/spec/rubocop/cop/code_reuse/finder_spec.rb b/spec/rubocop/cop/code_reuse/finder_spec.rb
index 484a1549a89..36f44ca79da 100644
--- a/spec/rubocop/cop/code_reuse/finder_spec.rb
+++ b/spec/rubocop/cop/code_reuse/finder_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/code_reuse/finder'
RSpec.describe RuboCop::Cop::CodeReuse::Finder do
diff --git a/spec/rubocop/cop/code_reuse/presenter_spec.rb b/spec/rubocop/cop/code_reuse/presenter_spec.rb
index 4639854588e..070a7ed760c 100644
--- a/spec/rubocop/cop/code_reuse/presenter_spec.rb
+++ b/spec/rubocop/cop/code_reuse/presenter_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/code_reuse/presenter'
RSpec.describe RuboCop::Cop::CodeReuse::Presenter do
diff --git a/spec/rubocop/cop/code_reuse/serializer_spec.rb b/spec/rubocop/cop/code_reuse/serializer_spec.rb
index 84db2e62b41..d5577caa2b4 100644
--- a/spec/rubocop/cop/code_reuse/serializer_spec.rb
+++ b/spec/rubocop/cop/code_reuse/serializer_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/code_reuse/serializer'
RSpec.describe RuboCop::Cop::CodeReuse::Serializer do
diff --git a/spec/rubocop/cop/code_reuse/service_class_spec.rb b/spec/rubocop/cop/code_reuse/service_class_spec.rb
index b6d94dd749f..353225b2c42 100644
--- a/spec/rubocop/cop/code_reuse/service_class_spec.rb
+++ b/spec/rubocop/cop/code_reuse/service_class_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/code_reuse/service_class'
RSpec.describe RuboCop::Cop::CodeReuse::ServiceClass do
diff --git a/spec/rubocop/cop/code_reuse/worker_spec.rb b/spec/rubocop/cop/code_reuse/worker_spec.rb
index 42c9303a93b..8155791a3e3 100644
--- a/spec/rubocop/cop/code_reuse/worker_spec.rb
+++ b/spec/rubocop/cop/code_reuse/worker_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/code_reuse/worker'
RSpec.describe RuboCop::Cop::CodeReuse::Worker do
diff --git a/spec/rubocop/cop/default_scope_spec.rb b/spec/rubocop/cop/default_scope_spec.rb
index 506843e030e..4fac0d465e0 100644
--- a/spec/rubocop/cop/default_scope_spec.rb
+++ b/spec/rubocop/cop/default_scope_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/default_scope'
RSpec.describe RuboCop::Cop::DefaultScope do
diff --git a/spec/rubocop/cop/destroy_all_spec.rb b/spec/rubocop/cop/destroy_all_spec.rb
index f6850a00238..468b10c3816 100644
--- a/spec/rubocop/cop/destroy_all_spec.rb
+++ b/spec/rubocop/cop/destroy_all_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/destroy_all'
RSpec.describe RuboCop::Cop::DestroyAll do
diff --git a/spec/rubocop/cop/filename_length_spec.rb b/spec/rubocop/cop/filename_length_spec.rb
index 2411c8dbc7b..ee128cb2781 100644
--- a/spec/rubocop/cop/filename_length_spec.rb
+++ b/spec/rubocop/cop/filename_length_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/filename_length'
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 f96e25c59e7..6d69eb5456f 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
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/avoid_uploaded_file_from_params'
RSpec.describe RuboCop::Cop::Gitlab::AvoidUploadedFileFromParams do
diff --git a/spec/rubocop/cop/gitlab/bulk_insert_spec.rb b/spec/rubocop/cop/gitlab/bulk_insert_spec.rb
index c280ab8fa8b..7c60518f890 100644
--- a/spec/rubocop/cop/gitlab/bulk_insert_spec.rb
+++ b/spec/rubocop/cop/gitlab/bulk_insert_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/bulk_insert'
RSpec.describe RuboCop::Cop::Gitlab::BulkInsert do
diff --git a/spec/rubocop/cop/gitlab/change_timezone_spec.rb b/spec/rubocop/cop/gitlab/change_timezone_spec.rb
index 9cb822ec4f2..f3c07e44cc7 100644
--- a/spec/rubocop/cop/gitlab/change_timezone_spec.rb
+++ b/spec/rubocop/cop/gitlab/change_timezone_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/change_timzone'
RSpec.describe RuboCop::Cop::Gitlab::ChangeTimezone do
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 19e5fe946be..1d99ec93e25 100644
--- a/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
+++ b/spec/rubocop/cop/gitlab/const_get_inherit_false_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/const_get_inherit_false'
RSpec.describe RuboCop::Cop::Gitlab::ConstGetInheritFalse do
diff --git a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
index a207155f432..3b3d5b01a30 100644
--- a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
+++ b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/duplicate_spec_location'
diff --git a/spec/rubocop/cop/gitlab/except_spec.rb b/spec/rubocop/cop/gitlab/except_spec.rb
index 7a122e3cf53..04cfe261cf2 100644
--- a/spec/rubocop/cop/gitlab/except_spec.rb
+++ b/spec/rubocop/cop/gitlab/except_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/except'
RSpec.describe RuboCop::Cop::Gitlab::Except do
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 03d7fc5e8b1..d2cd06d77c5 100644
--- a/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb
+++ b/spec/rubocop/cop/gitlab/finder_with_find_by_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/finder_with_find_by'
diff --git a/spec/rubocop/cop/gitlab/httparty_spec.rb b/spec/rubocop/cop/gitlab/httparty_spec.rb
index fcd18b0eb9b..98b1aa36586 100644
--- a/spec/rubocop/cop/gitlab/httparty_spec.rb
+++ b/spec/rubocop/cop/gitlab/httparty_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/httparty'
RSpec.describe RuboCop::Cop::Gitlab::HTTParty do # rubocop:disable RSpec/FilePath
diff --git a/spec/rubocop/cop/gitlab/intersect_spec.rb b/spec/rubocop/cop/gitlab/intersect_spec.rb
index 6f0367591cd..f3cb1412f35 100644
--- a/spec/rubocop/cop/gitlab/intersect_spec.rb
+++ b/spec/rubocop/cop/gitlab/intersect_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/intersect'
RSpec.describe RuboCop::Cop::Gitlab::Intersect do
diff --git a/spec/rubocop/cop/gitlab/json_spec.rb b/spec/rubocop/cop/gitlab/json_spec.rb
index 29c3b96cc1a..66b2c675e80 100644
--- a/spec/rubocop/cop/gitlab/json_spec.rb
+++ b/spec/rubocop/cop/gitlab/json_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/json'
RSpec.describe RuboCop::Cop::Gitlab::Json do
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 08634d5753a..d46dec3b2e3 100644
--- a/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb
+++ b/spec/rubocop/cop/gitlab/module_with_instance_variables_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/module_with_instance_variables'
RSpec.describe RuboCop::Cop::Gitlab::ModuleWithInstanceVariables do
diff --git a/spec/rubocop/cop/gitlab/namespaced_class_spec.rb b/spec/rubocop/cop/gitlab/namespaced_class_spec.rb
index d1f61aa5afb..824a1b8cef5 100644
--- a/spec/rubocop/cop/gitlab/namespaced_class_spec.rb
+++ b/spec/rubocop/cop/gitlab/namespaced_class_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/gitlab/namespaced_class'
diff --git a/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb b/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb
index 6dbbcdd8324..f73fc71b601 100644
--- a/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb
+++ b/spec/rubocop/cop/gitlab/policy_rule_boolean_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/policy_rule_boolean'
RSpec.describe RuboCop::Cop::Gitlab::PolicyRuleBoolean do
diff --git a/spec/rubocop/cop/gitlab/predicate_memoization_spec.rb b/spec/rubocop/cop/gitlab/predicate_memoization_spec.rb
index 071ddcf8b7d..903c02ba194 100644
--- a/spec/rubocop/cop/gitlab/predicate_memoization_spec.rb
+++ b/spec/rubocop/cop/gitlab/predicate_memoization_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/predicate_memoization'
RSpec.describe RuboCop::Cop::Gitlab::PredicateMemoization do
diff --git a/spec/rubocop/cop/gitlab/rails_logger_spec.rb b/spec/rubocop/cop/gitlab/rails_logger_spec.rb
index 7258b047191..24f49bf3044 100644
--- a/spec/rubocop/cop/gitlab/rails_logger_spec.rb
+++ b/spec/rubocop/cop/gitlab/rails_logger_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/rails_logger'
RSpec.describe RuboCop::Cop::Gitlab::RailsLogger do
diff --git a/spec/rubocop/cop/gitlab/union_spec.rb b/spec/rubocop/cop/gitlab/union_spec.rb
index 04a3db8e7dd..ce84c75338d 100644
--- a/spec/rubocop/cop/gitlab/union_spec.rb
+++ b/spec/rubocop/cop/gitlab/union_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/gitlab/union'
RSpec.describe RuboCop::Cop::Gitlab::Union do
diff --git a/spec/rubocop/cop/graphql/authorize_types_spec.rb b/spec/rubocop/cop/graphql/authorize_types_spec.rb
index 9242b865b20..6c521789e34 100644
--- a/spec/rubocop/cop/graphql/authorize_types_spec.rb
+++ b/spec/rubocop/cop/graphql/authorize_types_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/authorize_types'
@@ -63,4 +62,34 @@ RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes do
end
TYPE
end
+
+ it 'does not add an offense for subtypes of BaseUnion' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class AType < BaseUnion
+ possible_types Types::Foo, Types::Bar
+ end
+ end
+ TYPE
+ end
+
+ it 'does not add an offense for subtypes of BaseInputObject' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class AType < BaseInputObject
+ argument :a_thing
+ end
+ end
+ TYPE
+ end
+
+ it 'does not add an offense for InputTypes' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class AInputType < SomeObjectType
+ argument :a_thing
+ end
+ end
+ TYPE
+ end
end
diff --git a/spec/rubocop/cop/graphql/descriptions_spec.rb b/spec/rubocop/cop/graphql/descriptions_spec.rb
index 9ad40fad83d..af660aee165 100644
--- a/spec/rubocop/cop/graphql/descriptions_spec.rb
+++ b/spec/rubocop/cop/graphql/descriptions_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/descriptions'
RSpec.describe RuboCop::Cop::Graphql::Descriptions do
@@ -91,6 +90,50 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do
end
end
+ context 'enum values' do
+ it 'adds an offense when there is no description' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeEnum < BaseEnum
+ value 'FOO', value: 'foo'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Please add a `description` property.
+ end
+ end
+ TYPE
+ end
+
+ it 'adds an offense when description does not end in a period' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeEnum < BaseEnum
+ value 'FOO', value: 'foo', description: 'bar'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
+ end
+ end
+ TYPE
+ end
+
+ it 'does not add an offense when description is correct (defined using `description:`)' do
+ expect_no_offenses(<<~TYPE.strip)
+ module Types
+ class FakeEnum < BaseEnum
+ value 'FOO', value: 'foo', description: 'bar.'
+ end
+ end
+ TYPE
+ end
+
+ it 'does not add an offense when description is correct (defined as a second argument)' do
+ expect_no_offenses(<<~TYPE.strip)
+ module Types
+ class FakeEnum < BaseEnum
+ value 'FOO', 'bar.', value: 'foo'
+ end
+ end
+ TYPE
+ end
+ end
+
describe 'autocorrecting descriptions without periods' do
it 'can autocorrect' 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 d9a129244d6..47a6ce24d53 100644
--- a/spec/rubocop/cop/graphql/gid_expected_type_spec.rb
+++ b/spec/rubocop/cop/graphql/gid_expected_type_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/gid_expected_type'
diff --git a/spec/rubocop/cop/graphql/id_type_spec.rb b/spec/rubocop/cop/graphql/id_type_spec.rb
index 93c01cd7f06..a566488b118 100644
--- a/spec/rubocop/cop/graphql/id_type_spec.rb
+++ b/spec/rubocop/cop/graphql/id_type_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/id_type'
diff --git a/spec/rubocop/cop/graphql/json_type_spec.rb b/spec/rubocop/cop/graphql/json_type_spec.rb
index 91838c1708e..50437953c1d 100644
--- a/spec/rubocop/cop/graphql/json_type_spec.rb
+++ b/spec/rubocop/cop/graphql/json_type_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/json_type'
RSpec.describe RuboCop::Cop::Graphql::JSONType do
diff --git a/spec/rubocop/cop/graphql/resolver_type_spec.rb b/spec/rubocop/cop/graphql/resolver_type_spec.rb
index 11c0ad284a9..06bf90a8a07 100644
--- a/spec/rubocop/cop/graphql/resolver_type_spec.rb
+++ b/spec/rubocop/cop/graphql/resolver_type_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/resolver_type'
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 b3ec426dc07..2348552f9e4 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
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/group_public_or_visible_to_user'
RSpec.describe RuboCop::Cop::GroupPublicOrVisibleToUser do
diff --git a/spec/rubocop/cop/ignored_columns_spec.rb b/spec/rubocop/cop/ignored_columns_spec.rb
index 38b4ac0bc1a..1c72fedbf31 100644
--- a/spec/rubocop/cop/ignored_columns_spec.rb
+++ b/spec/rubocop/cop/ignored_columns_spec.rb
@@ -1,22 +1,17 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
-require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/ignored_columns'
RSpec.describe RuboCop::Cop::IgnoredColumns do
- include CopHelper
-
subject(:cop) { described_class.new }
- it 'flags the use of destroy_all with a local variable receiver' do
- inspect_source(<<~RUBY)
+ it 'flags direct use of ignored_columns instead of the IgnoredColumns concern' do
+ expect_offense(<<~RUBY)
class Foo < ApplicationRecord
self.ignored_columns += %i[id]
+ ^^^^^^^^^^^^^^^^^^^^ Use `IgnoredColumns` concern instead of adding to `self.ignored_columns`.
end
RUBY
-
- expect(cop.offenses.size).to eq(1)
end
end
diff --git a/spec/rubocop/cop/include_sidekiq_worker_spec.rb b/spec/rubocop/cop/include_sidekiq_worker_spec.rb
index bdd622d4894..8c706925ab9 100644
--- a/spec/rubocop/cop/include_sidekiq_worker_spec.rb
+++ b/spec/rubocop/cop/include_sidekiq_worker_spec.rb
@@ -2,7 +2,6 @@
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/include_sidekiq_worker'
RSpec.describe RuboCop::Cop::IncludeSidekiqWorker do
diff --git a/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb b/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
index 2d293fd0a05..8bfa57031d7 100644
--- a/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
+++ b/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/inject_enterprise_edition_module'
RSpec.describe RuboCop::Cop::InjectEnterpriseEditionModule do
diff --git a/spec/rubocop/cop/lint/last_keyword_argument_spec.rb b/spec/rubocop/cop/lint/last_keyword_argument_spec.rb
index aac59f0db4c..b1b4c88e0f6 100644
--- a/spec/rubocop/cop/lint/last_keyword_argument_spec.rb
+++ b/spec/rubocop/cop/lint/last_keyword_argument_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/lint/last_keyword_argument'
RSpec.describe RuboCop::Cop::Lint::LastKeywordArgument do
diff --git a/spec/rubocop/cop/migration/add_column_with_default_spec.rb b/spec/rubocop/cop/migration/add_column_with_default_spec.rb
index cf476ae55d6..3f47613280f 100644
--- a/spec/rubocop/cop/migration/add_column_with_default_spec.rb
+++ b/spec/rubocop/cop/migration/add_column_with_default_spec.rb
@@ -1,15 +1,12 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/add_column_with_default'
RSpec.describe RuboCop::Cop::Migration::AddColumnWithDefault do
- include CopHelper
-
let(:cop) { described_class.new }
- context 'outside of a migration' do
+ context 'when outside of a migration' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY)
def up
@@ -19,18 +16,16 @@ RSpec.describe RuboCop::Cop::Migration::AddColumnWithDefault do
end
end
- context 'in a migration' do
+ context 'when in a migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
- let(:offense) { '`add_column_with_default` is deprecated, use `add_column` instead' }
-
it 'registers an offense' do
expect_offense(<<~RUBY)
def up
add_column_with_default(:merge_request_diff_files, :artifacts, :boolean, default: true, allow_null: false)
- ^^^^^^^^^^^^^^^^^^^^^^^ #{offense}
+ ^^^^^^^^^^^^^^^^^^^^^^^ `add_column_with_default` is deprecated, use `add_column` instead
end
RUBY
end
diff --git a/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb b/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb
index 92863c45b1a..b78ec971245 100644
--- a/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb
+++ b/spec/rubocop/cop/migration/add_columns_to_wide_tables_spec.rb
@@ -1,15 +1,12 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/add_columns_to_wide_tables'
RSpec.describe RuboCop::Cop::Migration::AddColumnsToWideTables do
- include CopHelper
-
let(:cop) { described_class.new }
- context 'outside of a migration' do
+ context 'when outside of a migration' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY)
def up
@@ -19,14 +16,14 @@ RSpec.describe RuboCop::Cop::Migration::AddColumnsToWideTables do
end
end
- context 'in a migration' do
+ context 'when in a migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
context 'with wide tables' do
it 'registers an offense when adding a column to a wide table' do
- offense = '`projects` is a wide table with several columns, addig more should be avoided unless absolutely necessary. Consider storing the column in a different table or creating a new one.'
+ offense = '`projects` is a wide table with several columns, [...]'
expect_offense(<<~RUBY)
def up
@@ -37,7 +34,7 @@ RSpec.describe RuboCop::Cop::Migration::AddColumnsToWideTables do
end
it 'registers an offense when adding a column with default to a wide table' do
- offense = '`users` is a wide table with several columns, addig more should be avoided unless absolutely necessary. Consider storing the column in a different table or creating a new one.'
+ offense = '`users` is a wide table with several columns, [...]'
expect_offense(<<~RUBY)
def up
@@ -48,7 +45,7 @@ RSpec.describe RuboCop::Cop::Migration::AddColumnsToWideTables do
end
it 'registers an offense when adding a reference' do
- offense = '`ci_builds` is a wide table with several columns, addig more should be avoided unless absolutely necessary. Consider storing the column in a different table or creating a new one.'
+ offense = '`ci_builds` is a wide table with several columns, [...]'
expect_offense(<<~RUBY)
def up
@@ -59,7 +56,7 @@ RSpec.describe RuboCop::Cop::Migration::AddColumnsToWideTables do
end
it 'registers an offense when adding timestamps' do
- offense = '`projects` is a wide table with several columns, addig more should be avoided unless absolutely necessary. Consider storing the column in a different table or creating a new one.'
+ offense = '`projects` is a wide table with several columns, [...]'
expect_offense(<<~RUBY)
def up
diff --git a/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb b/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
index 25350ad1ecb..572c0d414b3 100644
--- a/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
+++ b/spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
@@ -1,50 +1,41 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/add_concurrent_foreign_key'
RSpec.describe RuboCop::Cop::Migration::AddConcurrentForeignKey do
- include CopHelper
-
let(:cop) { described_class.new }
- context 'outside of a migration' do
+ context 'when outside of a migration' do
it 'does not register any offenses' do
- inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end')
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses('def up; add_foreign_key(:projects, :users, column: :user_id); end')
end
end
- context 'in a migration' do
+ context 'when in a migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
it 'registers an offense when using add_foreign_key' do
- inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id); end')
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def up
+ add_foreign_key(:projects, :users, column: :user_id)
+ ^^^^^^^^^^^^^^^ `add_foreign_key` requires downtime, use `add_concurrent_foreign_key` instead
+ end
+ RUBY
end
it 'does not register an offense when a `NOT VALID` foreign key is added' do
- inspect_source('def up; add_foreign_key(:projects, :users, column: :user_id, validate: false); end')
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses('def up; add_foreign_key(:projects, :users, column: :user_id, validate: false); end')
end
it 'does not register an offense when `add_foreign_key` is within `with_lock_retries`' do
- inspect_source <<~RUBY
+ expect_no_offenses(<<~RUBY)
with_lock_retries do
add_foreign_key :key, :projects, column: :project_id, on_delete: :cascade
end
RUBY
-
- expect(cop.offenses).to be_empty
end
end
end
diff --git a/spec/rubocop/cop/migration/add_concurrent_index_spec.rb b/spec/rubocop/cop/migration/add_concurrent_index_spec.rb
index 351283a230a..52b3a5769ff 100644
--- a/spec/rubocop/cop/migration/add_concurrent_index_spec.rb
+++ b/spec/rubocop/cop/migration/add_concurrent_index_spec.rb
@@ -1,40 +1,33 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/add_concurrent_index'
RSpec.describe RuboCop::Cop::Migration::AddConcurrentIndex do
- include CopHelper
-
subject(:cop) { described_class.new }
- context 'in migration' do
+ context 'when in migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
it 'registers an offense when add_concurrent_index is used inside a change method' do
- inspect_source('def change; add_concurrent_index :table, :column; end')
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def change
+ ^^^^^^ `add_concurrent_index` is not reversible[...]
+ add_concurrent_index :table, :column
+ end
+ RUBY
end
it 'registers no offense when add_concurrent_index is used inside an up method' do
- inspect_source('def up; add_concurrent_index :table, :column; end')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses('def up; add_concurrent_index :table, :column; end')
end
end
- context 'outside of migration' do
+ context 'when outside of migration' do
it 'registers no offense' do
- inspect_source('def change; add_concurrent_index :table, :column; end')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses('def change; add_concurrent_index :table, :column; end')
end
end
end
diff --git a/spec/rubocop/cop/migration/add_index_spec.rb b/spec/rubocop/cop/migration/add_index_spec.rb
index 1d083e9f2d2..088bfe434f4 100644
--- a/spec/rubocop/cop/migration/add_index_spec.rb
+++ b/spec/rubocop/cop/migration/add_index_spec.rb
@@ -1,12 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/add_index'
RSpec.describe RuboCop::Cop::Migration::AddIndex do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'in migration' do
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 149fb0a48eb..f4695ff8d2d 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
@@ -1,15 +1,14 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/add_limit_to_text_columns'
RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns do
- include CopHelper
-
subject(:cop) { described_class.new }
- context 'in migration' do
+ context 'when in migration' do
+ let(:msg) { 'Text columns should always have a limit set (255 is suggested)[...]' }
+
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
@@ -25,31 +24,29 @@ RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns do
create_table :test_text_limits, id: false do |t|
t.integer :test_id, null: false
t.text :name
- ^^^^ #{described_class::MSG}
+ ^^^^ #{msg}
end
create_table_with_constraints :test_text_limits_create do |t|
t.integer :test_id, null: false
t.text :title
t.text :description
- ^^^^ #{described_class::MSG}
+ ^^^^ #{msg}
t.text_limit :title, 100
end
add_column :test_text_limits, :email, :text
- ^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^ #{msg}
add_column_with_default :test_text_limits, :role, :text, default: 'default'
- ^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
change_column_type_concurrently :test_text_limits, :test_id, :text
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
end
end
RUBY
-
- expect(cop.offenses.map(&:cop_name)).to all(eq('Migration/AddLimitToTextColumns'))
end
end
@@ -111,7 +108,7 @@ RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns do
end
# Make sure that the cop is properly checking for an `add_text_limit`
- # over the same {table, attribute} as the one that triggered the offence
+ # over the same {table, attribute} as the one that triggered the offense
context 'when the limit is defined for a same name attribute but different table' do
it 'registers an offense' do
expect_offense(<<~RUBY)
@@ -123,17 +120,17 @@ RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns do
create_table :test_text_limits, id: false do |t|
t.integer :test_id, null: false
t.text :name
- ^^^^ #{described_class::MSG}
+ ^^^^ #{msg}
end
add_column :test_text_limits, :email, :text
- ^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^ #{msg}
add_column_with_default :test_text_limits, :role, :text, default: 'default'
- ^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
change_column_type_concurrently :test_text_limits, :test_id, :text
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
add_text_limit :wrong_table, :name, 255
add_text_limit :wrong_table, :email, 255
@@ -142,8 +139,6 @@ RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns do
end
end
RUBY
-
- expect(cop.offenses.map(&:cop_name)).to all(eq('Migration/AddLimitToTextColumns'))
end
end
@@ -176,18 +171,18 @@ RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns do
DOWNTIME = false
def up
- drop_table :no_offence_on_down
+ drop_table :no_offense_on_down
end
def down
- create_table :no_offence_on_down, id: false do |t|
+ create_table :no_offense_on_down, id: false do |t|
t.integer :test_id, null: false
t.text :name
end
- add_column :no_offence_on_down, :email, :text
+ add_column :no_offense_on_down, :email, :text
- add_column_with_default :no_offence_on_down, :role, :text, default: 'default'
+ add_column_with_default :no_offense_on_down, :role, :text, default: 'default'
end
end
RUBY
@@ -195,7 +190,7 @@ RSpec.describe RuboCop::Cop::Migration::AddLimitToTextColumns do
end
end
- context 'outside of migration' do
+ context 'when outside of migration' do
it 'registers no offense' do
expect_no_offenses(<<~RUBY)
class TestTextLimits < ActiveRecord::Migration[6.0]
diff --git a/spec/rubocop/cop/migration/add_reference_spec.rb b/spec/rubocop/cop/migration/add_reference_spec.rb
index 6e229d3eefc..9445780e9ed 100644
--- a/spec/rubocop/cop/migration/add_reference_spec.rb
+++ b/spec/rubocop/cop/migration/add_reference_spec.rb
@@ -1,15 +1,12 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/add_reference'
RSpec.describe RuboCop::Cop::Migration::AddReference do
- include CopHelper
-
let(:cop) { described_class.new }
- context 'outside of a migration' do
+ context 'when outside of a migration' do
it 'does not register any offenses' do
expect_no_offenses(<<~RUBY)
def up
@@ -19,12 +16,12 @@ RSpec.describe RuboCop::Cop::Migration::AddReference do
end
end
- context 'in a migration' do
+ context 'when in a migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
- let(:offense) { '`add_reference` requires downtime for existing tables, use `add_concurrent_foreign_key` instead. When used for new tables, `index: true` or `index: { options... } is required.`' }
+ let(:offense) { '`add_reference` requires downtime for existing tables, use `add_concurrent_foreign_key`[...]' }
context 'when the table existed before' do
it 'registers an offense when using add_reference' do
diff --git a/spec/rubocop/cop/migration/add_timestamps_spec.rb b/spec/rubocop/cop/migration/add_timestamps_spec.rb
index 83570711ab9..ef5a856722f 100644
--- a/spec/rubocop/cop/migration/add_timestamps_spec.rb
+++ b/spec/rubocop/cop/migration/add_timestamps_spec.rb
@@ -1,12 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/add_timestamps'
RSpec.describe RuboCop::Cop::Migration::AddTimestamps do
- include CopHelper
-
subject(:cop) { described_class.new }
let(:migration_with_add_timestamps) do
@@ -47,44 +44,39 @@ RSpec.describe RuboCop::Cop::Migration::AddTimestamps do
)
end
- context 'in migration' do
+ context 'when in migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
it 'registers an offense when the "add_timestamps" method is used' do
- inspect_source(migration_with_add_timestamps)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([7])
- end
+ expect_offense(<<~RUBY)
+ class Users < ActiveRecord::Migration[4.2]
+ DOWNTIME = false
+
+ def change
+ add_column(:users, :username, :text)
+ add_timestamps(:users)
+ ^^^^^^^^^^^^^^ Do not use `add_timestamps`, use `add_timestamps_with_timezone` instead
+ end
+ end
+ RUBY
end
it 'does not register an offense when the "add_timestamps" method is not used' do
- inspect_source(migration_without_add_timestamps)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(0)
- end
+ expect_no_offenses(migration_without_add_timestamps)
end
it 'does not register an offense when the "add_timestamps_with_timezone" method is used' do
- inspect_source(migration_with_add_timestamps_with_timezone)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(0)
- end
+ expect_no_offenses(migration_with_add_timestamps_with_timezone)
end
end
- context 'outside of migration' do
- it 'registers no offense' do
- inspect_source(migration_with_add_timestamps)
- inspect_source(migration_without_add_timestamps)
- inspect_source(migration_with_add_timestamps_with_timezone)
-
- expect(cop.offenses.size).to eq(0)
+ context 'when outside of migration' do
+ it 'registers no offense', :aggregate_failures do
+ expect_no_offenses(migration_with_add_timestamps)
+ expect_no_offenses(migration_without_add_timestamps)
+ expect_no_offenses(migration_with_add_timestamps_with_timezone)
end
end
end
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 38ccf546b7c..15e947a1e53 100644
--- a/spec/rubocop/cop/migration/complex_indexes_require_name_spec.rb
+++ b/spec/rubocop/cop/migration/complex_indexes_require_name_spec.rb
@@ -1,15 +1,14 @@
# frozen_string_literal: true
#
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/complex_indexes_require_name'
RSpec.describe RuboCop::Cop::Migration::ComplexIndexesRequireName do
- include CopHelper
-
subject(:cop) { described_class.new }
- context 'in migration' do
+ context 'when in migration' do
+ let(:msg) { 'indexes added with custom options must be explicitly named' }
+
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
@@ -29,9 +28,9 @@ RSpec.describe RuboCop::Cop::Migration::ComplexIndexesRequireName do
t.index :column1, unique: true
t.index :column2, where: 'column1 = 0'
- ^^^^^ #{described_class::MSG}
+ ^^^^^ #{msg}
t.index :column3, using: :gin
- ^^^^^ #{described_class::MSG}
+ ^^^^^ #{msg}
end
end
@@ -40,8 +39,6 @@ RSpec.describe RuboCop::Cop::Migration::ComplexIndexesRequireName do
end
end
RUBY
-
- expect(cop.offenses.map(&:cop_name)).to all(eq("Migration/#{described_class.name.demodulize}"))
end
end
@@ -85,20 +82,18 @@ RSpec.describe RuboCop::Cop::Migration::ComplexIndexesRequireName do
add_index :test_indexes, :column1
add_index :test_indexes, :column2, where: "column2 = 'value'", order: { column4: :desc }
- ^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^ #{msg}
end
def down
add_index :test_indexes, :column4, 'unique' => true, where: 'column4 IS NOT NULL'
- ^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^ #{msg}
add_concurrent_index :test_indexes, :column6, using: :gin, opclass: :gin_trgm_ops
- ^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^^^^^^^^ #{msg}
end
end
RUBY
-
- expect(cop.offenses.map(&:cop_name)).to all(eq("Migration/#{described_class.name.demodulize}"))
end
end
@@ -132,7 +127,7 @@ RSpec.describe RuboCop::Cop::Migration::ComplexIndexesRequireName do
end
end
- context 'outside migration' do
+ context 'when outside migration' do
before do
allow(cop).to receive(:in_migration?).and_return(false)
end
diff --git a/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb b/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb
index 2159bad1490..7bcaf36b014 100644
--- a/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb
+++ b/spec/rubocop/cop/migration/create_table_with_foreign_keys_spec.rb
@@ -1,12 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/create_table_with_foreign_keys'
RSpec.describe RuboCop::Cop::Migration::CreateTableWithForeignKeys do
- include CopHelper
-
let(:cop) { described_class.new }
context 'outside of a migration' do
@@ -22,7 +19,7 @@ RSpec.describe RuboCop::Cop::Migration::CreateTableWithForeignKeys do
end
end
- context 'in a migration' do
+ context 'when in a migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
diff --git a/spec/rubocop/cop/migration/datetime_spec.rb b/spec/rubocop/cop/migration/datetime_spec.rb
index a3cccae21e0..3854ddfe99c 100644
--- a/spec/rubocop/cop/migration/datetime_spec.rb
+++ b/spec/rubocop/cop/migration/datetime_spec.rb
@@ -1,44 +1,11 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/datetime'
RSpec.describe RuboCop::Cop::Migration::Datetime do
- include CopHelper
-
subject(:cop) { described_class.new }
- let(:create_table_migration_with_datetime) do
- %q(
- class Users < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- def change
- create_table :users do |t|
- t.string :username, null: false
- t.datetime :last_sign_in
- end
- end
- end
- )
- end
-
- let(:create_table_migration_with_timestamp) do
- %q(
- class Users < ActiveRecord::Migration[6.0]
- DOWNTIME = false
-
- def change
- create_table :users do |t|
- t.string :username, null: false
- t.timestamp :last_sign_in
- end
- end
- end
- )
- end
-
let(:create_table_migration_without_datetime) do
%q(
class Users < ActiveRecord::Migration[6.0]
@@ -120,92 +87,94 @@ RSpec.describe RuboCop::Cop::Migration::Datetime do
)
end
- context 'in migration' do
+ context 'when in migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
it 'registers an offense when the ":datetime" data type is used on create_table' do
- inspect_source(create_table_migration_with_datetime)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([8])
- expect(cop.offenses.first.message).to include('`datetime`')
- end
+ expect_offense(<<~RUBY)
+ class Users < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ create_table :users do |t|
+ t.string :username, null: false
+ t.datetime :last_sign_in
+ ^^^^^^^^ Do not use the `datetime` data type[...]
+ end
+ end
+ end
+ RUBY
end
it 'registers an offense when the ":timestamp" data type is used on create_table' do
- inspect_source(create_table_migration_with_timestamp)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([8])
- expect(cop.offenses.first.message).to include('timestamp')
- end
+ expect_offense(<<~RUBY)
+ class Users < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ create_table :users do |t|
+ t.string :username, null: false
+ t.timestamp :last_sign_in
+ ^^^^^^^^^ Do not use the `timestamp` data type[...]
+ end
+ end
+ end
+ RUBY
end
it 'does not register an offense when the ":datetime" data type is not used on create_table' do
- inspect_source(create_table_migration_without_datetime)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(0)
- end
+ expect_no_offenses(create_table_migration_without_datetime)
end
it 'does not register an offense when the ":datetime_with_timezone" data type is used on create_table' do
- inspect_source(create_table_migration_with_datetime_with_timezone)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(0)
- end
+ expect_no_offenses(create_table_migration_with_datetime_with_timezone)
end
it 'registers an offense when the ":datetime" data type is used on add_column' do
- inspect_source(add_column_migration_with_datetime)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([7])
- expect(cop.offenses.first.message).to include('`datetime`')
- end
+ expect_offense(<<~RUBY)
+ class Users < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column(:users, :username, :text)
+ add_column(:users, :last_sign_in, :datetime)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use the `datetime` data type[...]
+ end
+ end
+ RUBY
end
it 'registers an offense when the ":timestamp" data type is used on add_column' do
- inspect_source(add_column_migration_with_timestamp)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([7])
- expect(cop.offenses.first.message).to include('timestamp')
- end
+ expect_offense(<<~RUBY)
+ class Users < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ def change
+ add_column(:users, :username, :text)
+ add_column(:users, :last_sign_in, :timestamp)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use the `timestamp` data type[...]
+ end
+ end
+ RUBY
end
it 'does not register an offense when the ":datetime" data type is not used on add_column' do
- inspect_source(add_column_migration_without_datetime)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(0)
- end
+ expect_no_offenses(add_column_migration_without_datetime)
end
it 'does not register an offense when the ":datetime_with_timezone" data type is used on add_column' do
- inspect_source(add_column_migration_with_datetime_with_timezone)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(0)
- end
+ expect_no_offenses(add_column_migration_with_datetime_with_timezone)
end
end
- context 'outside of migration' do
- it 'registers no offense' do
- inspect_source(add_column_migration_with_datetime)
- inspect_source(add_column_migration_with_timestamp)
- inspect_source(add_column_migration_without_datetime)
- inspect_source(add_column_migration_with_datetime_with_timezone)
-
- expect(cop.offenses.size).to eq(0)
+ context 'when outside of migration' do
+ it 'registers no offense', :aggregate_failures do
+ expect_no_offenses(add_column_migration_with_datetime)
+ expect_no_offenses(add_column_migration_with_timestamp)
+ expect_no_offenses(add_column_migration_without_datetime)
+ expect_no_offenses(add_column_migration_with_datetime_with_timezone)
end
end
end
diff --git a/spec/rubocop/cop/migration/drop_table_spec.rb b/spec/rubocop/cop/migration/drop_table_spec.rb
index d783cb56203..f1bd710f5e6 100644
--- a/spec/rubocop/cop/migration/drop_table_spec.rb
+++ b/spec/rubocop/cop/migration/drop_table_spec.rb
@@ -1,15 +1,16 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/drop_table'
RSpec.describe RuboCop::Cop::Migration::DropTable do
- include CopHelper
-
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.'
+ end
+
before do
allow(cop).to receive(:in_deployment_migration?).and_return(true)
end
@@ -30,7 +31,7 @@ RSpec.describe RuboCop::Cop::Migration::DropTable do
expect_offense(<<~PATTERN)
def up
drop_table :table
- ^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^ #{msg}
end
PATTERN
end
@@ -41,7 +42,7 @@ RSpec.describe RuboCop::Cop::Migration::DropTable do
expect_offense(<<~PATTERN)
def change
drop_table :table
- ^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^ #{msg}
end
PATTERN
end
@@ -63,7 +64,7 @@ RSpec.describe RuboCop::Cop::Migration::DropTable do
expect_offense(<<~PATTERN)
def up
execute "DROP TABLE table"
- ^^^^^^^ #{described_class::MSG}
+ ^^^^^^^ #{msg}
end
PATTERN
end
@@ -74,7 +75,7 @@ RSpec.describe RuboCop::Cop::Migration::DropTable do
expect_offense(<<~PATTERN)
def change
execute "DROP TABLE table"
- ^^^^^^^ #{described_class::MSG}
+ ^^^^^^^ #{msg}
end
PATTERN
end
diff --git a/spec/rubocop/cop/migration/hash_index_spec.rb b/spec/rubocop/cop/migration/hash_index_spec.rb
index 15f68eb990f..6da27af39b6 100644
--- a/spec/rubocop/cop/migration/hash_index_spec.rb
+++ b/spec/rubocop/cop/migration/hash_index_spec.rb
@@ -1,52 +1,47 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/hash_index'
RSpec.describe RuboCop::Cop::Migration::HashIndex do
- include CopHelper
-
subject(:cop) { described_class.new }
- context 'in migration' do
+ context 'when in migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
it 'registers an offense when creating a hash index' do
- inspect_source('def change; add_index :table, :column, using: :hash; end')
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def change
+ add_index :table, :column, using: :hash
+ ^^^^^^^^^^^^ hash indexes should be avoided at all costs[...]
+ end
+ RUBY
end
it 'registers an offense when creating a concurrent hash index' do
- inspect_source('def change; add_concurrent_index :table, :column, using: :hash; end')
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def change
+ add_concurrent_index :table, :column, using: :hash
+ ^^^^^^^^^^^^ hash indexes should be avoided at all costs[...]
+ end
+ RUBY
end
it 'registers an offense when creating a hash index using t.index' do
- inspect_source('def change; t.index :table, :column, using: :hash; end')
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def change
+ t.index :table, :column, using: :hash
+ ^^^^^^^^^^^^ hash indexes should be avoided at all costs[...]
+ end
+ RUBY
end
end
- context 'outside of migration' do
+ context 'when outside of migration' do
it 'registers no offense' do
- inspect_source('def change; index :table, :column, using: :hash; end')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses('def change; index :table, :column, using: :hash; end')
end
end
end
diff --git a/spec/rubocop/cop/migration/prevent_strings_spec.rb b/spec/rubocop/cop/migration/prevent_strings_spec.rb
index 560a485017a..a9b62f23a77 100644
--- a/spec/rubocop/cop/migration/prevent_strings_spec.rb
+++ b/spec/rubocop/cop/migration/prevent_strings_spec.rb
@@ -1,49 +1,44 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/prevent_strings'
RSpec.describe RuboCop::Cop::Migration::PreventStrings do
- include CopHelper
-
subject(:cop) { described_class.new }
- context 'in migration' do
+ context 'when in migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
context 'when the string data type is used' do
it 'registers an offense' do
- expect_offense(<<~RUBY)
+ expect_offense(<<~RUBY, msg: "Do not use the `string` data type, use `text` instead.[...]")
class Users < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
create_table :users do |t|
t.string :username, null: false
- ^^^^^^ #{described_class::MSG}
+ ^^^^^^ %{msg}
t.timestamps_with_timezone null: true
t.string :password
- ^^^^^^ #{described_class::MSG}
+ ^^^^^^ %{msg}
end
add_column(:users, :bio, :string)
- ^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^ %{msg}
add_column_with_default(:users, :url, :string, default: '/-/user', allow_null: false, limit: 255)
- ^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
change_column_type_concurrently :users, :commit_id, :string
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
end
end
RUBY
-
- expect(cop.offenses.map(&:cop_name)).to all(eq('Migration/PreventStrings'))
end
end
@@ -109,7 +104,7 @@ RSpec.describe RuboCop::Cop::Migration::PreventStrings do
end
end
- context 'on down' do
+ context 'when using down method' do
it 'registers no offense' do
expect_no_offenses(<<~RUBY)
class Users < ActiveRecord::Migration[6.0]
@@ -138,7 +133,7 @@ RSpec.describe RuboCop::Cop::Migration::PreventStrings do
end
end
- context 'outside of migration' do
+ context 'when outside of migration' do
it 'registers no offense' do
expect_no_offenses(<<~RUBY)
class Users < ActiveRecord::Migration[6.0]
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 a25328a56a8..b3e66492d83 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
@@ -1,22 +1,19 @@
# frozen_string_literal: true
#
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/refer_to_index_by_name'
RSpec.describe RuboCop::Cop::Migration::ReferToIndexByName do
- include CopHelper
-
subject(:cop) { described_class.new }
- context 'in migration' do
+ context 'when in migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
context 'when existing indexes are referred to without an explicit name' do
it 'registers an offense' do
- expect_offense(<<~RUBY)
+ expect_offense(<<~RUBY, msg: 'migration methods that refer to existing indexes must do so by name')
class TestReferToIndexByName < ActiveRecord::Migration[6.0]
DOWNTIME = false
@@ -30,22 +27,22 @@ RSpec.describe RuboCop::Cop::Migration::ReferToIndexByName do
end
if index_exists? :test_indexes, :column2
- ^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^ %{msg}
remove_index :test_indexes, :column2
- ^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^ %{msg}
end
remove_index :test_indexes, column: column3
- ^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^ %{msg}
remove_index :test_indexes, name: 'index_name_4'
end
def down
if index_exists? :test_indexes, :column4, using: :gin, opclass: :gin_trgm_ops
- ^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^ %{msg}
remove_concurrent_index :test_indexes, :column4, using: :gin, opclass: :gin_trgm_ops
- ^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG}
+ ^^^^^^^^^^^^^^^^^^^^^^^ %{msg}
end
if index_exists? :test_indexes, :column3, unique: true, name: 'index_name_3', where: 'column3 = 10'
@@ -54,13 +51,11 @@ RSpec.describe RuboCop::Cop::Migration::ReferToIndexByName do
end
end
RUBY
-
- expect(cop.offenses.map(&:cop_name)).to all(eq("Migration/#{described_class.name.demodulize}"))
end
end
end
- context 'outside migration' do
+ context 'when outside migration' do
before do
allow(cop).to receive(:in_migration?).and_return(false)
end
diff --git a/spec/rubocop/cop/migration/remove_column_spec.rb b/spec/rubocop/cop/migration/remove_column_spec.rb
index 4768093b10d..f72a5b048d5 100644
--- a/spec/rubocop/cop/migration/remove_column_spec.rb
+++ b/spec/rubocop/cop/migration/remove_column_spec.rb
@@ -1,67 +1,58 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/remove_column'
RSpec.describe RuboCop::Cop::Migration::RemoveColumn do
- include CopHelper
-
subject(:cop) { described_class.new }
def source(meth = 'change')
"def #{meth}; remove_column :table, :column; end"
end
- context 'in a regular migration' do
+ context 'when in a regular migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
allow(cop).to receive(:in_post_deployment_migration?).and_return(false)
end
it 'registers an offense when remove_column is used in the change method' do
- inspect_source(source('change'))
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def change
+ remove_column :table, :column
+ ^^^^^^^^^^^^^ `remove_column` must only be used in post-deployment migrations
+ end
+ RUBY
end
it 'registers an offense when remove_column is used in the up method' do
- inspect_source(source('up'))
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def up
+ remove_column :table, :column
+ ^^^^^^^^^^^^^ `remove_column` must only be used in post-deployment migrations
+ end
+ RUBY
end
it 'registers no offense when remove_column is used in the down method' do
- inspect_source(source('down'))
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses(source('down'))
end
end
- context 'in a post-deployment migration' do
+ context 'when in a post-deployment migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
allow(cop).to receive(:in_post_deployment_migration?).and_return(true)
end
it 'registers no offense' do
- inspect_source(source)
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses(source)
end
end
- context 'outside of a migration' do
+ context 'when outside of a migration' do
it 'registers no offense' do
- inspect_source(source)
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses(source)
end
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 8da368d588c..10ca0353b0f 100644
--- a/spec/rubocop/cop/migration/remove_concurrent_index_spec.rb
+++ b/spec/rubocop/cop/migration/remove_concurrent_index_spec.rb
@@ -1,12 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/remove_concurrent_index'
RSpec.describe RuboCop::Cop::Migration::RemoveConcurrentIndex do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'in migration' do
@@ -15,26 +12,22 @@ RSpec.describe RuboCop::Cop::Migration::RemoveConcurrentIndex do
end
it 'registers an offense when remove_concurrent_index is used inside a change method' do
- inspect_source('def change; remove_concurrent_index :table, :column; end')
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def change
+ ^^^^^^ `remove_concurrent_index` is not reversible [...]
+ remove_concurrent_index :table, :column
+ end
+ RUBY
end
it 'registers no offense when remove_concurrent_index is used inside an up method' do
- inspect_source('def up; remove_concurrent_index :table, :column; end')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses('def up; remove_concurrent_index :table, :column; end')
end
end
context 'outside of migration' do
it 'registers no offense' do
- inspect_source('def change; remove_concurrent_index :table, :column; end')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses('def change; remove_concurrent_index :table, :column; end')
end
end
end
diff --git a/spec/rubocop/cop/migration/remove_index_spec.rb b/spec/rubocop/cop/migration/remove_index_spec.rb
index 274c907ac41..5d1ffef2589 100644
--- a/spec/rubocop/cop/migration/remove_index_spec.rb
+++ b/spec/rubocop/cop/migration/remove_index_spec.rb
@@ -1,34 +1,29 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/remove_index'
RSpec.describe RuboCop::Cop::Migration::RemoveIndex do
- include CopHelper
-
subject(:cop) { described_class.new }
- context 'in migration' do
+ context 'when in migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
it 'registers an offense when remove_index is used' do
- inspect_source('def change; remove_index :table, :column; end')
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def change
+ remove_index :table, :column
+ ^^^^^^^^^^^^ `remove_index` requires downtime, use `remove_concurrent_index` instead
+ end
+ RUBY
end
end
- context 'outside of migration' do
+ context 'when outside of migration' do
it 'registers no offense' do
- inspect_source('def change; remove_index :table, :column; end')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses('def change; remove_index :table, :column; end')
end
end
end
diff --git a/spec/rubocop/cop/migration/safer_boolean_column_spec.rb b/spec/rubocop/cop/migration/safer_boolean_column_spec.rb
index aa7bb58ab45..cf9bdbeef91 100644
--- a/spec/rubocop/cop/migration/safer_boolean_column_spec.rb
+++ b/spec/rubocop/cop/migration/safer_boolean_column_spec.rb
@@ -1,12 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/safer_boolean_column'
RSpec.describe RuboCop::Cop::Migration::SaferBooleanColumn do
- include CopHelper
-
subject(:cop) { described_class.new }
context 'in migration' do
@@ -31,11 +28,10 @@ RSpec.describe RuboCop::Cop::Migration::SaferBooleanColumn do
sources_and_offense.each do |source, offense|
context "given the source \"#{source}\"" do
it "registers the offense matching \"#{offense}\"" do
- inspect_source(source)
-
- aggregate_failures do
- expect(cop.offenses.first.message).to match(offense)
- end
+ expect_offense(<<~RUBY, node: source, msg: offense)
+ %{node}
+ ^{node} Boolean columns on the `#{table}` table %{msg}.[...]
+ RUBY
end
end
end
@@ -48,11 +44,7 @@ RSpec.describe RuboCop::Cop::Migration::SaferBooleanColumn do
inoffensive_sources.each do |source|
context "given the source \"#{source}\"" do
it "registers no offense" do
- inspect_source(source)
-
- aggregate_failures do
- expect(cop.offenses).to be_empty
- end
+ expect_no_offenses(source)
end
end
end
@@ -60,25 +52,19 @@ RSpec.describe RuboCop::Cop::Migration::SaferBooleanColumn do
end
it 'registers no offense for tables not listed in SMALL_TABLES' do
- inspect_source("add_column :large_table, :column, :boolean")
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses("add_column :large_table, :column, :boolean")
end
it 'registers no offense for non-boolean columns' do
table = described_class::SMALL_TABLES.sample
- inspect_source("add_column :#{table}, :column, :string")
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses("add_column :#{table}, :column, :string")
end
end
context 'outside of migration' do
it 'registers no offense' do
table = described_class::SMALL_TABLES.sample
- inspect_source("add_column :#{table}, :column, :boolean")
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses("add_column :#{table}, :column, :boolean")
end
end
end
diff --git a/spec/rubocop/cop/migration/schedule_async_spec.rb b/spec/rubocop/cop/migration/schedule_async_spec.rb
index a7246dfa73a..b89acb6db41 100644
--- a/spec/rubocop/cop/migration/schedule_async_spec.rb
+++ b/spec/rubocop/cop/migration/schedule_async_spec.rb
@@ -2,14 +2,9 @@
require 'fast_spec_helper'
-require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../../rubocop/cop/migration/schedule_async'
RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
- include CopHelper
-
let(:cop) { described_class.new }
let(:source) do
<<~SOURCE
@@ -21,9 +16,7 @@ RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
shared_examples 'a disabled cop' do
it 'does not register any offenses' do
- inspect_source(source)
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses(source)
end
end
@@ -50,101 +43,73 @@ RSpec.describe RuboCop::Cop::Migration::ScheduleAsync do
end
context 'BackgroundMigrationWorker.perform_async' do
- it 'adds an offence when calling `BackgroundMigrationWorker.peform_async`' do
- inspect_source(source)
-
- expect(cop.offenses.size).to eq(1)
- end
-
- it 'autocorrects to the right version' do
- correct_source = <<~CORRECT
- def up
- migrate_async(ClazzName, "Bar", "Baz")
- end
- CORRECT
+ it 'adds an offense when calling `BackgroundMigrationWorker.peform_async` and corrects', :aggregate_failures do
+ expect_offense(<<~RUBY)
+ def up
+ BackgroundMigrationWorker.perform_async(ClazzName, "Bar", "Baz")
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
+ end
+ RUBY
- expect(autocorrect_source(source)).to eq(correct_source)
+ expect_correction(<<~RUBY)
+ def up
+ migrate_async(ClazzName, "Bar", "Baz")
+ end
+ RUBY
end
end
context 'BackgroundMigrationWorker.perform_in' do
- let(:source) do
- <<~SOURCE
+ it 'adds an offense and corrects', :aggregate_failures do
+ expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
.perform_in(delay, ClazzName, "Bar", "Baz")
end
- SOURCE
- end
-
- it 'adds an offence' do
- inspect_source(source)
+ RUBY
- expect(cop.offenses.size).to eq(1)
- end
-
- it 'autocorrects to the right version' do
- correct_source = <<~CORRECT
+ expect_correction(<<~RUBY)
def up
migrate_in(delay, ClazzName, "Bar", "Baz")
end
- CORRECT
-
- expect(autocorrect_source(source)).to eq(correct_source)
+ RUBY
end
end
context 'BackgroundMigrationWorker.bulk_perform_async' do
- let(:source) do
- <<~SOURCE
+ it 'adds an offense and corrects', :aggregate_failures do
+ expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
.bulk_perform_async(jobs)
end
- SOURCE
- end
-
- it 'adds an offence' do
- inspect_source(source)
-
- expect(cop.offenses.size).to eq(1)
- end
+ RUBY
- it 'autocorrects to the right version' do
- correct_source = <<~CORRECT
+ expect_correction(<<~RUBY)
def up
bulk_migrate_async(jobs)
end
- CORRECT
-
- expect(autocorrect_source(source)).to eq(correct_source)
+ RUBY
end
end
context 'BackgroundMigrationWorker.bulk_perform_in' do
- let(:source) do
- <<~SOURCE
+ it 'adds an offense and corrects', :aggregate_failures do
+ expect_offense(<<~RUBY)
def up
BackgroundMigrationWorker
+ ^^^^^^^^^^^^^^^^^^^^^^^^^ Don't call [...]
.bulk_perform_in(5.minutes, jobs)
end
- SOURCE
- end
-
- it 'adds an offence' do
- inspect_source(source)
+ RUBY
- expect(cop.offenses.size).to eq(1)
- end
-
- it 'autocorrects to the right version' do
- correct_source = <<~CORRECT
+ expect_correction(<<~RUBY)
def up
bulk_migrate_in(5.minutes, jobs)
end
- CORRECT
-
- expect(autocorrect_source(source)).to eq(correct_source)
+ RUBY
end
end
end
diff --git a/spec/rubocop/cop/migration/timestamps_spec.rb b/spec/rubocop/cop/migration/timestamps_spec.rb
index 2f4154907d2..91bb5c1b05b 100644
--- a/spec/rubocop/cop/migration/timestamps_spec.rb
+++ b/spec/rubocop/cop/migration/timestamps_spec.rb
@@ -1,12 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/timestamps'
RSpec.describe RuboCop::Cop::Migration::Timestamps do
- include CopHelper
-
subject(:cop) { described_class.new }
let(:migration_with_timestamps) do
@@ -62,38 +59,36 @@ RSpec.describe RuboCop::Cop::Migration::Timestamps do
end
it 'registers an offense when the "timestamps" method is used' do
- inspect_source(migration_with_timestamps)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([8])
- end
+ expect_offense(<<~RUBY)
+ class Users < ActiveRecord::Migration[4.2]
+ DOWNTIME = false
+
+ def change
+ create_table :users do |t|
+ t.string :username, null: false
+ t.timestamps null: true
+ ^^^^^^^^^^ Do not use `timestamps`, use `timestamps_with_timezone` instead
+ t.string :password
+ end
+ end
+ end
+ RUBY
end
it 'does not register an offense when the "timestamps" method is not used' do
- inspect_source(migration_without_timestamps)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(0)
- end
+ expect_no_offenses(migration_without_timestamps)
end
it 'does not register an offense when the "timestamps_with_timezone" method is used' do
- inspect_source(migration_with_timestamps_with_timezone)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(0)
- end
+ expect_no_offenses(migration_with_timestamps_with_timezone)
end
end
context 'outside of migration' do
- it 'registers no offense' do
- inspect_source(migration_with_timestamps)
- inspect_source(migration_without_timestamps)
- inspect_source(migration_with_timestamps_with_timezone)
-
- expect(cop.offenses.size).to eq(0)
+ it 'registers no offense', :aggregate_failures do
+ expect_no_offenses(migration_with_timestamps)
+ expect_no_offenses(migration_without_timestamps)
+ expect_no_offenses(migration_with_timestamps_with_timezone)
end
end
end
diff --git a/spec/rubocop/cop/migration/update_column_in_batches_spec.rb b/spec/rubocop/cop/migration/update_column_in_batches_spec.rb
index 8049cba12d0..a12ae94c22b 100644
--- a/spec/rubocop/cop/migration/update_column_in_batches_spec.rb
+++ b/spec/rubocop/cop/migration/update_column_in_batches_spec.rb
@@ -2,9 +2,6 @@
require 'fast_spec_helper'
-require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../../rubocop/cop/migration/update_column_in_batches'
RSpec.describe RuboCop::Cop::Migration::UpdateColumnInBatches do
@@ -31,9 +28,7 @@ RSpec.describe RuboCop::Cop::Migration::UpdateColumnInBatches do
context 'outside of a migration' do
it 'does not register any offenses' do
- inspect_source(migration_code)
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses(migration_code)
end
end
@@ -53,14 +48,14 @@ RSpec.describe RuboCop::Cop::Migration::UpdateColumnInBatches do
let(:relative_spec_filepath) { Pathname.new(spec_filepath).relative_path_from(tmp_rails_root) }
it 'registers an offense when using update_column_in_batches' do
- inspect_source(migration_code, @migration_file)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([2])
- expect(cop.offenses.first.message)
- .to include("`#{relative_spec_filepath}`")
- end
+ expect_offense(<<~RUBY, @migration_file)
+ def up
+ update_column_in_batches(:projects, :name, "foo") do |table, query|
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Migration running `update_column_in_batches` [...]
+ query.where(table[:name].eq(nil))
+ end
+ end
+ RUBY
end
end
@@ -76,20 +71,18 @@ RSpec.describe RuboCop::Cop::Migration::UpdateColumnInBatches do
end
it 'does not register any offenses' do
- inspect_source(migration_code, @migration_file)
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses(migration_code)
end
end
- context 'in a migration' do
+ context 'when in migration' do
let(:migration_filepath) { File.join(tmp_rails_root, 'db', 'migrate', '20121220064453_my_super_migration.rb') }
it_behaves_like 'a migration file with no spec file'
it_behaves_like 'a migration file with a spec file'
end
- context 'in a post migration' do
+ context 'when in a post migration' do
let(:migration_filepath) { File.join(tmp_rails_root, 'db', 'post_migrate', '20121220064453_my_super_migration.rb') }
it_behaves_like 'a migration file with no spec file'
@@ -99,14 +92,14 @@ RSpec.describe RuboCop::Cop::Migration::UpdateColumnInBatches do
context 'EE migrations' do
let(:spec_filepath) { File.join(tmp_rails_root, 'ee', 'spec', 'migrations', 'my_super_migration_spec.rb') }
- context 'in a migration' do
+ context 'when in a migration' do
let(:migration_filepath) { File.join(tmp_rails_root, 'ee', 'db', 'migrate', '20121220064453_my_super_migration.rb') }
it_behaves_like 'a migration file with no spec file'
it_behaves_like 'a migration file with a spec file'
end
- context 'in a post migration' do
+ context 'when in a post migration' do
let(:migration_filepath) { File.join(tmp_rails_root, 'ee', 'db', 'post_migrate', '20121220064453_my_super_migration.rb') }
it_behaves_like 'a migration file with no spec file'
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 814d87ea24b..298ca273256 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
@@ -1,64 +1,58 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/with_lock_retries_disallowed_method'
RSpec.describe RuboCop::Cop::Migration::WithLockRetriesDisallowedMethod do
- include CopHelper
-
subject(:cop) { described_class.new }
- context 'in migration' do
+ context 'when in migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
it 'registers an offense when `with_lock_retries` block has disallowed method' do
- inspect_source('def change; with_lock_retries { disallowed_method }; end')
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def change
+ with_lock_retries { disallowed_method }
+ ^^^^^^^^^^^^^^^^^ The method is not allowed [...]
+ end
+ RUBY
end
it 'registers an offense when `with_lock_retries` block has disallowed methods' do
- source = <<~HEREDOC
- def change
- with_lock_retries do
- disallowed_method
+ expect_offense(<<~RUBY)
+ def change
+ with_lock_retries do
+ disallowed_method
+ ^^^^^^^^^^^^^^^^^ The method is not allowed [...]
- create_table do |t|
- t.text :text
- end
+ create_table do |t|
+ t.text :text
+ end
- other_disallowed_method
+ other_disallowed_method
+ ^^^^^^^^^^^^^^^^^^^^^^^ The method is not allowed [...]
- add_column :users, :name
+ add_column :users, :name
+ end
end
- end
- HEREDOC
-
- inspect_source(source)
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(2)
- expect(cop.offenses.map(&:line)).to eq([3, 9])
- end
+ RUBY
end
it 'registers no offense when `with_lock_retries` has only allowed method' do
- inspect_source('def up; with_lock_retries { add_foreign_key :foo, :bar }; end')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses(<<~RUBY)
+ def up
+ with_lock_retries { add_foreign_key :foo, :bar }
+ end
+ RUBY
end
describe 'for `add_foreign_key`' do
it 'registers an offense when more than two FKs are added' do
message = described_class::MSG_ONLY_ONE_FK_ALLOWED
- expect_offense <<~RUBY
+ expect_offense(<<~RUBY)
with_lock_retries do
add_foreign_key :imports, :projects, column: :project_id, on_delete: :cascade
^^^^^^^^^^^^^^^ #{message}
@@ -71,11 +65,13 @@ RSpec.describe RuboCop::Cop::Migration::WithLockRetriesDisallowedMethod do
end
end
- context 'outside of migration' do
+ context 'when outside of migration' do
it 'registers no offense' do
- inspect_source('def change; with_lock_retries { disallowed_method }; end')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses(<<~RUBY)
+ def change
+ with_lock_retries { disallowed_method }
+ end
+ RUBY
end
end
end
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 f0be14c8ee9..f2e84a8697c 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
@@ -1,40 +1,41 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/migration/with_lock_retries_with_change'
RSpec.describe RuboCop::Cop::Migration::WithLockRetriesWithChange do
- include CopHelper
-
subject(:cop) { described_class.new }
- context 'in migration' do
+ context 'when in migration' do
before do
allow(cop).to receive(:in_migration?).and_return(true)
end
it 'registers an offense when `with_lock_retries` is used inside a `change` method' do
- inspect_source('def change; with_lock_retries {}; end')
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- end
+ expect_offense(<<~RUBY)
+ def change
+ ^^^^^^ `with_lock_retries` cannot be used within `change` [...]
+ with_lock_retries {}
+ end
+ RUBY
end
it 'registers no offense when `with_lock_retries` is used inside an `up` method' do
- inspect_source('def up; with_lock_retries {}; end')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses(<<~RUBY)
+ def up
+ with_lock_retries {}
+ end
+ RUBY
end
end
- context 'outside of migration' do
+ context 'when outside of migration' do
it 'registers no offense' do
- inspect_source('def change; with_lock_retries {}; end')
-
- expect(cop.offenses.size).to eq(0)
+ expect_no_offenses(<<~RUBY)
+ def change
+ with_lock_retries {}
+ end
+ RUBY
end
end
end
diff --git a/spec/rubocop/cop/performance/ar_count_each_spec.rb b/spec/rubocop/cop/performance/ar_count_each_spec.rb
index 402e3e93147..fa7a1aba426 100644
--- a/spec/rubocop/cop/performance/ar_count_each_spec.rb
+++ b/spec/rubocop/cop/performance/ar_count_each_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/performance/ar_count_each.rb'
RSpec.describe RuboCop::Cop::Performance::ARCountEach 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 8497ff0e909..127c858a549 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
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/performance/ar_exists_and_present_blank.rb'
RSpec.describe RuboCop::Cop::Performance::ARExistsAndPresentBlank do
diff --git a/spec/rubocop/cop/performance/readlines_each_spec.rb b/spec/rubocop/cop/performance/readlines_each_spec.rb
index 5a30107722a..0a8b168ce5d 100644
--- a/spec/rubocop/cop/performance/readlines_each_spec.rb
+++ b/spec/rubocop/cop/performance/readlines_each_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/performance/readlines_each'
RSpec.describe RuboCop::Cop::Performance::ReadlinesEach do
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 dc665f9dd25..1261ca7891c 100644
--- a/spec/rubocop/cop/prefer_class_methods_over_module_spec.rb
+++ b/spec/rubocop/cop/prefer_class_methods_over_module_spec.rb
@@ -1,16 +1,12 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
-require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/prefer_class_methods_over_module'
RSpec.describe RuboCop::Cop::PreferClassMethodsOverModule do
- include CopHelper
-
subject(:cop) { described_class.new }
- it 'flags violation when using module ClassMethods' do
+ it 'flags violation when using module ClassMethods and corrects', :aggregate_failures do
expect_offense(<<~RUBY)
module Foo
extend ActiveSupport::Concern
@@ -22,6 +18,17 @@ RSpec.describe RuboCop::Cop::PreferClassMethodsOverModule do
end
end
RUBY
+
+ expect_correction(<<~RUBY)
+ module Foo
+ extend ActiveSupport::Concern
+
+ class_methods do
+ def a_class_method
+ end
+ end
+ end
+ RUBY
end
it "doesn't flag violation when using class_methods" do
@@ -69,30 +76,4 @@ RSpec.describe RuboCop::Cop::PreferClassMethodsOverModule do
end
RUBY
end
-
- it 'autocorrects ClassMethods into class_methods' do
- source = <<~RUBY
- module Foo
- extend ActiveSupport::Concern
-
- module ClassMethods
- def a_class_method
- end
- end
- end
- RUBY
- autocorrected = autocorrect_source(source)
-
- expected_source = <<~RUBY
- module Foo
- extend ActiveSupport::Concern
-
- class_methods do
- def a_class_method
- end
- end
- end
- RUBY
- expect(autocorrected).to eq(expected_source)
- end
end
diff --git a/spec/rubocop/cop/project_path_helper_spec.rb b/spec/rubocop/cop/project_path_helper_spec.rb
index 16782802a27..b3c920f9d25 100644
--- a/spec/rubocop/cop/project_path_helper_spec.rb
+++ b/spec/rubocop/cop/project_path_helper_spec.rb
@@ -2,7 +2,6 @@
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/project_path_helper'
RSpec.describe RuboCop::Cop::ProjectPathHelper do
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 46b50d7690b..366fc4b5657 100644
--- a/spec/rubocop/cop/put_group_routes_under_scope_spec.rb
+++ b/spec/rubocop/cop/put_group_routes_under_scope_spec.rb
@@ -1,12 +1,9 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/put_group_routes_under_scope'
RSpec.describe RuboCop::Cop::PutGroupRoutesUnderScope do
- include CopHelper
-
subject(:cop) { described_class.new }
%w[resource resources get post put patch delete].each do |route_method|
@@ -15,12 +12,12 @@ RSpec.describe RuboCop::Cop::PutGroupRoutesUnderScope do
marker = '^' * offense.size
expect_offense(<<~PATTERN)
- scope(path: 'groups/*group_id/-', module: :groups) do
- resource :issues
- end
+ scope(path: 'groups/*group_id/-', module: :groups) do
+ resource :issues
+ end
- #{offense}
- #{marker} Put new group routes under /-/ scope
+ #{offense}
+ #{marker} Put new group routes under /-/ scope
PATTERN
end
end
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 eb783d22129..9d226db09ef 100644
--- a/spec/rubocop/cop/put_project_routes_under_scope_spec.rb
+++ b/spec/rubocop/cop/put_project_routes_under_scope_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/put_project_routes_under_scope'
RSpec.describe RuboCop::Cop::PutProjectRoutesUnderScope do
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 9332ab4186e..9335b8d01ee 100644
--- a/spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb
+++ b/spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/qa/ambiguous_page_object_name'
diff --git a/spec/rubocop/cop/qa/element_with_pattern_spec.rb b/spec/rubocop/cop/qa/element_with_pattern_spec.rb
index 28c351ccf1e..d3e79525c62 100644
--- a/spec/rubocop/cop/qa/element_with_pattern_spec.rb
+++ b/spec/rubocop/cop/qa/element_with_pattern_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/qa/element_with_pattern'
diff --git a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
index 050f0396fac..678e62048b8 100644
--- a/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
+++ b/spec/rubocop/cop/rspec/be_success_matcher_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/be_success_matcher'
RSpec.describe RuboCop::Cop::RSpec::BeSuccessMatcher do
diff --git a/spec/rubocop/cop/rspec/env_assignment_spec.rb b/spec/rubocop/cop/rspec/env_assignment_spec.rb
index cc132d1532a..da6bb2fa2fb 100644
--- a/spec/rubocop/cop/rspec/env_assignment_spec.rb
+++ b/spec/rubocop/cop/rspec/env_assignment_spec.rb
@@ -2,7 +2,6 @@
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/env_assignment'
RSpec.describe RuboCop::Cop::RSpec::EnvAssignment do
diff --git a/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb b/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb
index d1ce8d01e0b..e36feecdd66 100644
--- a/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb
+++ b/spec/rubocop/cop/rspec/expect_gitlab_tracking_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/expect_gitlab_tracking'
RSpec.describe RuboCop::Cop::RSpec::ExpectGitlabTracking do
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 8beec53375e..74c1521fa0e 100644
--- a/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
+++ b/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
@@ -2,7 +2,6 @@
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/factories_in_migration_specs'
RSpec.describe RuboCop::Cop::RSpec::FactoriesInMigrationSpecs do
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 0e6af71ea3e..194e2436ff2 100644
--- a/spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb
+++ b/spec/rubocop/cop/rspec/factory_bot/inline_association_spec.rb
@@ -2,7 +2,6 @@
require 'fast_spec_helper'
require 'rspec-parameterized'
-require 'rubocop'
require_relative '../../../../../rubocop/cop/rspec/factory_bot/inline_association'
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 c2d97c8992a..9bdbe145f4c 100644
--- a/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb
+++ b/spec/rubocop/cop/rspec/have_gitlab_http_status_spec.rb
@@ -3,7 +3,6 @@
require 'fast_spec_helper'
require 'rspec-parameterized'
-require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/have_gitlab_http_status'
RSpec.describe RuboCop::Cop::RSpec::HaveGitlabHttpStatus do
diff --git a/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb b/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb
index ffabbae90dc..7a2b7c92bd1 100644
--- a/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb
+++ b/spec/rubocop/cop/rspec/modify_sidekiq_middleware_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/modify_sidekiq_middleware'
RSpec.describe RuboCop::Cop::RSpec::ModifySidekiqMiddleware do
diff --git a/spec/rubocop/cop/rspec/timecop_freeze_spec.rb b/spec/rubocop/cop/rspec/timecop_freeze_spec.rb
index 939623f8299..b8d16d58d9e 100644
--- a/spec/rubocop/cop/rspec/timecop_freeze_spec.rb
+++ b/spec/rubocop/cop/rspec/timecop_freeze_spec.rb
@@ -2,7 +2,6 @@
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/timecop_freeze'
RSpec.describe RuboCop::Cop::RSpec::TimecopFreeze do
diff --git a/spec/rubocop/cop/rspec/timecop_travel_spec.rb b/spec/rubocop/cop/rspec/timecop_travel_spec.rb
index 476e45e69a6..16e09fb8c45 100644
--- a/spec/rubocop/cop/rspec/timecop_travel_spec.rb
+++ b/spec/rubocop/cop/rspec/timecop_travel_spec.rb
@@ -2,7 +2,6 @@
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/timecop_travel'
RSpec.describe RuboCop::Cop::RSpec::TimecopTravel do
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 23531cd0201..78e6bec51d4 100644
--- a/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb
+++ b/spec/rubocop/cop/rspec/top_level_describe_path_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/rspec/top_level_describe_path'
RSpec.describe RuboCop::Cop::RSpec::TopLevelDescribePath do
diff --git a/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb b/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb
index cacf0a1b67d..c21999be917 100644
--- a/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb
+++ b/spec/rubocop/cop/ruby_interpolation_in_translation_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/ruby_interpolation_in_translation'
diff --git a/spec/rubocop/cop/safe_params_spec.rb b/spec/rubocop/cop/safe_params_spec.rb
index 62f8e542d86..9a064b93b16 100644
--- a/spec/rubocop/cop/safe_params_spec.rb
+++ b/spec/rubocop/cop/safe_params_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../rubocop/cop/safe_params'
RSpec.describe RuboCop::Cop::SafeParams do
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 a19ddf9dbe6..01afaf3acb6 100644
--- a/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb
+++ b/spec/rubocop/cop/scalability/bulk_perform_with_context_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/scalability/bulk_perform_with_context'
RSpec.describe RuboCop::Cop::Scalability::BulkPerformWithContext do
diff --git a/spec/rubocop/cop/scalability/cron_worker_context_spec.rb b/spec/rubocop/cop/scalability/cron_worker_context_spec.rb
index 11b2b82d2f5..28db12fd075 100644
--- a/spec/rubocop/cop/scalability/cron_worker_context_spec.rb
+++ b/spec/rubocop/cop/scalability/cron_worker_context_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/scalability/cron_worker_context'
RSpec.describe RuboCop::Cop::Scalability::CronWorkerContext do
diff --git a/spec/rubocop/cop/scalability/file_uploads_spec.rb b/spec/rubocop/cop/scalability/file_uploads_spec.rb
index bda5c056b03..ca25b0246f0 100644
--- a/spec/rubocop/cop/scalability/file_uploads_spec.rb
+++ b/spec/rubocop/cop/scalability/file_uploads_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/scalability/file_uploads'
RSpec.describe RuboCop::Cop::Scalability::FileUploads do
diff --git a/spec/rubocop/cop/scalability/idempotent_worker_spec.rb b/spec/rubocop/cop/scalability/idempotent_worker_spec.rb
index 729f2613697..53c0c06f6c9 100644
--- a/spec/rubocop/cop/scalability/idempotent_worker_spec.rb
+++ b/spec/rubocop/cop/scalability/idempotent_worker_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/scalability/idempotent_worker'
RSpec.describe RuboCop::Cop::Scalability::IdempotentWorker do
diff --git a/spec/rubocop/cop/sidekiq_options_queue_spec.rb b/spec/rubocop/cop/sidekiq_options_queue_spec.rb
index 306cbcf62b5..346a8d82475 100644
--- a/spec/rubocop/cop/sidekiq_options_queue_spec.rb
+++ b/spec/rubocop/cop/sidekiq_options_queue_spec.rb
@@ -2,29 +2,19 @@
require 'fast_spec_helper'
-require 'rubocop'
-require 'rubocop/rspec/support'
-
require_relative '../../../rubocop/cop/sidekiq_options_queue'
RSpec.describe RuboCop::Cop::SidekiqOptionsQueue do
- include CopHelper
-
subject(:cop) { described_class.new }
it 'registers an offense when `sidekiq_options` is used with the `queue` option' do
- inspect_source('sidekiq_options queue: "some_queue"')
-
- aggregate_failures do
- expect(cop.offenses.size).to eq(1)
- expect(cop.offenses.map(&:line)).to eq([1])
- expect(cop.highlights).to eq(['queue: "some_queue"'])
- end
+ expect_offense(<<~CODE)
+ sidekiq_options queue: "some_queue"
+ ^^^^^^^^^^^^^^^^^^^ Do not manually set a queue; `ApplicationWorker` sets one automatically.
+ CODE
end
it 'does not register an offense when `sidekiq_options` is used with another option' do
- inspect_source('sidekiq_options retry: false')
-
- expect(cop.offenses).to be_empty
+ expect_no_offenses('sidekiq_options retry: false')
end
end
diff --git a/spec/rubocop/cop/static_translation_definition_spec.rb b/spec/rubocop/cop/static_translation_definition_spec.rb
index 8656b07a6e4..b2b04cbcbde 100644
--- a/spec/rubocop/cop/static_translation_definition_spec.rb
+++ b/spec/rubocop/cop/static_translation_definition_spec.rb
@@ -2,7 +2,6 @@
require 'fast_spec_helper'
-require 'rubocop'
require 'rspec-parameterized'
require_relative '../../../rubocop/cop/static_translation_definition'
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 b6711effe9e..f377dfe36d8 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
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/usage_data/distinct_count_by_large_foreign_key'
diff --git a/spec/rubocop/cop/usage_data/large_table_spec.rb b/spec/rubocop/cop/usage_data/large_table_spec.rb
index 26bd4e61625..a6b22fd7f0d 100644
--- a/spec/rubocop/cop/usage_data/large_table_spec.rb
+++ b/spec/rubocop/cop/usage_data/large_table_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require_relative '../../../../rubocop/cop/usage_data/large_table'
diff --git a/spec/rubocop/migration_helpers_spec.rb b/spec/rubocop/migration_helpers_spec.rb
index f0be21c9d70..997d4071c29 100644
--- a/spec/rubocop/migration_helpers_spec.rb
+++ b/spec/rubocop/migration_helpers_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require 'rspec-parameterized'
require_relative '../../rubocop/migration_helpers'
diff --git a/spec/rubocop/qa_helpers_spec.rb b/spec/rubocop/qa_helpers_spec.rb
index cf6d2f1a845..4b5566609e3 100644
--- a/spec/rubocop/qa_helpers_spec.rb
+++ b/spec/rubocop/qa_helpers_spec.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require 'rubocop'
require 'parser/current'
require_relative '../../rubocop/qa_helpers'