summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop/graphql
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 11:59:07 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 11:59:07 +0000
commit8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch)
tree544930fb309b30317ae9797a9683768705d664c4 /spec/rubocop/cop/graphql
parent4b1de649d0168371549608993deac953eb692019 (diff)
downloadgitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/rubocop/cop/graphql')
-rw-r--r--spec/rubocop/cop/graphql/descriptions_spec.rb102
1 files changed, 92 insertions, 10 deletions
diff --git a/spec/rubocop/cop/graphql/descriptions_spec.rb b/spec/rubocop/cop/graphql/descriptions_spec.rb
index 3b29cd2fbee..f4693057bcb 100644
--- a/spec/rubocop/cop/graphql/descriptions_spec.rb
+++ b/spec/rubocop/cop/graphql/descriptions_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions, type: :rubocop do
subject(:cop) { described_class.new }
context 'fields' do
- it 'adds an offense when there is no field description' do
+ it 'adds an offense when there is no description' do
inspect_source(<<~TYPE)
module Types
class FakeType < BaseObject
@@ -24,24 +24,37 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions, type: :rubocop do
expect(cop.offenses.size).to eq 1
end
- it 'does not add an offense for fields with a description' do
- expect_no_offenses(<<~TYPE.strip)
+ it 'adds an offense when description does not end in a period' do
+ inspect_source(<<~TYPE)
module Types
class FakeType < BaseObject
- graphql_name 'FakeTypeName'
-
- argument :a_thing,
+ field :a_thing,
GraphQL::STRING_TYPE,
null: false,
description: 'A descriptive description'
end
end
TYPE
+
+ expect(cop.offenses.size).to eq 1
+ end
+
+ it 'does not add an offense when description is correct' do
+ expect_no_offenses(<<~TYPE.strip)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: 'A descriptive description.'
+ end
+ end
+ TYPE
end
end
context 'arguments' do
- it 'adds an offense when there is no argument description' do
+ it 'adds an offense when there is no description' do
inspect_source(<<~TYPE)
module Types
class FakeType < BaseObject
@@ -55,19 +68,88 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions, type: :rubocop do
expect(cop.offenses.size).to eq 1
end
- it 'does not add an offense for arguments with a description' do
- expect_no_offenses(<<~TYPE.strip)
+ it 'adds an offense when description does not end in a period' do
+ inspect_source(<<~TYPE)
module Types
class FakeType < BaseObject
- graphql_name 'FakeTypeName'
+ argument :a_thing,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: 'Behold! A description'
+ end
+ end
+ TYPE
+ expect(cop.offenses.size).to eq 1
+ end
+
+ it 'does not add an offense when description is correct' do
+ expect_no_offenses(<<~TYPE.strip)
+ module Types
+ class FakeType < BaseObject
argument :a_thing,
GraphQL::STRING_TYPE,
null: false,
+ description: 'Behold! A description.'
+ end
+ end
+ TYPE
+ end
+ end
+
+ describe 'autocorrecting descriptions without periods' do
+ it 'can autocorrect' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ ^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
+ GraphQL::STRING_TYPE,
+ null: false,
description: 'Behold! A description'
end
end
TYPE
+
+ expect_correction(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: 'Behold! A description.'
+ end
+ end
+ TYPE
+ end
+
+ it 'can autocorrect a heredoc' do
+ expect_offense(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ ^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: <<~DESC
+ Behold! A description
+ DESC
+ end
+ end
+ TYPE
+
+ expect_correction(<<~TYPE)
+ module Types
+ class FakeType < BaseObject
+ field :a_thing,
+ GraphQL::STRING_TYPE,
+ null: false,
+ description: <<~DESC
+ Behold! A description.
+ DESC
+ end
+ end
+ TYPE
end
end
end