summaryrefslogtreecommitdiff
path: root/spec/rubocop
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 06:07:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 06:07:11 +0000
commit75621c94b5dbe233edd72c3d8cc602fed25e84d2 (patch)
treea38d832241e66a2e296e276493bff0260bfc9712 /spec/rubocop
parent9bf8cb8d34039f3cef9e1b2f812ce634f2bebe69 (diff)
downloadgitlab-ce-75621c94b5dbe233edd72c3d8cc602fed25e84d2.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/graphql/resource_not_available_error_spec.rb37
-rw-r--r--spec/rubocop/node_pattern_helper_spec.rb20
2 files changed, 57 insertions, 0 deletions
diff --git a/spec/rubocop/cop/graphql/resource_not_available_error_spec.rb b/spec/rubocop/cop/graphql/resource_not_available_error_spec.rb
new file mode 100644
index 00000000000..6003b9f3954
--- /dev/null
+++ b/spec/rubocop/cop/graphql/resource_not_available_error_spec.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+
+require_relative '../../../../rubocop/cop/graphql/resource_not_available_error'
+
+RSpec.describe RuboCop::Cop::Graphql::ResourceNotAvailableError, feature_category: :shared do
+ shared_examples 'flagging and auto-correction' do |exception|
+ it "flags and auto-corrects `raise #{exception}`" do
+ expect_offense(<<~'RUBY', exception: exception)
+ raise %{exception}
+ ^^^^^^^{exception} Prefer using `raise_resource_not_available_error!` instead.
+
+ raise %{exception}, 'message ' \
+ ^^^^^^^{exception}^^^^^^^^^^^^^^ Prefer using `raise_resource_not_available_error!` instead.
+ 'with new lines'
+ RUBY
+
+ expect_correction(<<~'RUBY')
+ raise_resource_not_available_error!
+
+ raise_resource_not_available_error! 'message ' \
+ 'with new lines'
+ RUBY
+ end
+ end
+
+ it_behaves_like 'flagging and auto-correction', 'Gitlab::Graphql::Errors::ResourceNotAvailable'
+ it_behaves_like 'flagging and auto-correction', '::Gitlab::Graphql::Errors::ResourceNotAvailable'
+
+ it 'does not flag unrelated exceptions' do
+ expect_no_offenses(<<~RUBY)
+ raise Gitlab::Graphql::Errors::ResourceVeryAvailable
+ raise ::Gitlab::Graphql::Errors::ResourceVeryAvailable
+ RUBY
+ end
+end
diff --git a/spec/rubocop/node_pattern_helper_spec.rb b/spec/rubocop/node_pattern_helper_spec.rb
new file mode 100644
index 00000000000..a141e81b618
--- /dev/null
+++ b/spec/rubocop/node_pattern_helper_spec.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+require 'rubocop_spec_helper'
+
+require_relative '../../rubocop/node_pattern_helper'
+
+RSpec.describe RuboCop::NodePatternHelper, feature_category: :tooling do
+ include described_class
+
+ describe '#const_pattern' do
+ it 'returns nested const node patterns' do
+ expect(const_pattern('Foo')).to eq('(const {nil? cbase} :Foo)')
+ expect(const_pattern('Foo::Bar')).to eq('(const (const {nil? cbase} :Foo) :Bar)')
+ end
+
+ it 'returns nested const node patterns with custom parent' do
+ expect(const_pattern('Foo::Bar', parent: 'nil?')).to eq('(const (const nil? :Foo) :Bar)')
+ end
+ end
+end