diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
commit | b595cb0c1dec83de5bdee18284abe86614bed33b (patch) | |
tree | 8c3d4540f193c5ff98019352f554e921b3a41a72 /spec/rubocop | |
parent | 2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff) |
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'spec/rubocop')
-rw-r--r-- | spec/rubocop/cop/database/rescue_query_canceled_spec.rb | 29 | ||||
-rw-r--r-- | spec/rubocop/cop/database/rescue_statement_timeout_spec.rb | 29 | ||||
-rw-r--r-- | spec/rubocop/cop/gitlab/namespaced_class_spec.rb | 6 |
3 files changed, 61 insertions, 3 deletions
diff --git a/spec/rubocop/cop/database/rescue_query_canceled_spec.rb b/spec/rubocop/cop/database/rescue_query_canceled_spec.rb new file mode 100644 index 00000000000..56314a18bf5 --- /dev/null +++ b/spec/rubocop/cop/database/rescue_query_canceled_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require_relative '../../../../rubocop/cop/database/rescue_query_canceled' + +RSpec.describe RuboCop::Cop::Database::RescueQueryCanceled do + subject(:cop) { described_class.new } + + it 'flags the use of ActiveRecord::QueryCanceled' do + expect_offense(<<~CODE) + begin + do_something + rescue ActiveRecord::QueryCanceled => e + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid rescuing the `ActiveRecord::QueryCanceled` [...] + try_something_else + end + CODE + end + + it 'does not flag a different exception' do + expect_no_offenses(<<~CODE) + begin + do_something + rescue ActiveRecord::RecordNotFound => e + try_something_else + end + CODE + end +end diff --git a/spec/rubocop/cop/database/rescue_statement_timeout_spec.rb b/spec/rubocop/cop/database/rescue_statement_timeout_spec.rb new file mode 100644 index 00000000000..b9b2ce1c16b --- /dev/null +++ b/spec/rubocop/cop/database/rescue_statement_timeout_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require_relative '../../../../rubocop/cop/database/rescue_statement_timeout' + +RSpec.describe RuboCop::Cop::Database::RescueStatementTimeout do + subject(:cop) { described_class.new } + + it 'flags the use of ActiveRecord::StatementTimeout' do + expect_offense(<<~CODE) + begin + do_something + rescue ActiveRecord::StatementTimeout => e + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid rescuing the `ActiveRecord::StatementTimeout` [...] + try_something_else + end + CODE + end + + it 'does not flag a different exception' do + expect_no_offenses(<<~CODE) + begin + do_something + rescue ActiveRecord::RecordNotFound => e + try_something_else + end + CODE + end +end diff --git a/spec/rubocop/cop/gitlab/namespaced_class_spec.rb b/spec/rubocop/cop/gitlab/namespaced_class_spec.rb index d9209a8672c..83d0eaf4884 100644 --- a/spec/rubocop/cop/gitlab/namespaced_class_spec.rb +++ b/spec/rubocop/cop/gitlab/namespaced_class_spec.rb @@ -20,7 +20,7 @@ RSpec.describe RuboCop::Cop::Gitlab::NamespacedClass do it 'flags a class definition without additional namespace' do expect_offense(namespaced(<<~SOURCE)) class MyClass - ^^^^^^^^^^^^^ #{described_class::MSG} + ^^^^^^^ #{described_class::MSG} end SOURCE end @@ -28,7 +28,7 @@ RSpec.describe RuboCop::Cop::Gitlab::NamespacedClass do it 'flags a compact class definition without additional namespace' do expect_offense(<<~SOURCE, namespace: namespace) class %{namespace}::MyClass - ^{namespace}^^^^^^^^^^^^^^^ #{described_class::MSG} + ^{namespace}^^^^^^^^^ #{described_class::MSG} end SOURCE end @@ -36,7 +36,7 @@ RSpec.describe RuboCop::Cop::Gitlab::NamespacedClass do it 'flags a class definition with inheritance without additional namespace' do expect_offense(namespaced(<<~SOURCE)) class MyClass < ApplicationRecord - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG} + ^^^^^^^ #{described_class::MSG} def some_method true end |