debian-mirror-gitlab/spec/rubocop/cop/graphql/descriptions_spec.rb

150 lines
3.9 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
require 'fast_spec_helper'
require 'rubocop'
require_relative '../../../../rubocop/cop/graphql/descriptions'
2021-03-08 18:12:59 +05:30
RSpec.describe RuboCop::Cop::Graphql::Descriptions do
2019-12-04 20:38:33 +05:30
subject(:cop) { described_class.new }
context 'fields' do
2021-02-22 17:27:13 +05:30
it 'adds an offense when there is no description' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~TYPE)
2019-12-04 20:38:33 +05:30
module Types
class FakeType < BaseObject
field :a_thing,
2021-03-11 19:13:27 +05:30
^^^^^^^^^^^^^^^ Please add a `description` property.
2019-12-04 20:38:33 +05:30
GraphQL::STRING_TYPE,
null: false
end
end
TYPE
end
2021-02-22 17:27:13 +05:30
it 'adds an offense when description does not end in a period' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~TYPE)
2019-12-04 20:38:33 +05:30
module Types
class FakeType < BaseObject
2021-02-22 17:27:13 +05:30
field :a_thing,
2021-03-11 19:13:27 +05:30
^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
2019-12-04 20:38:33 +05:30
GraphQL::STRING_TYPE,
null: false,
description: 'A descriptive description'
end
end
TYPE
2021-02-22 17:27:13 +05:30
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
2019-12-04 20:38:33 +05:30
end
end
context 'arguments' do
2021-02-22 17:27:13 +05:30
it 'adds an offense when there is no description' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~TYPE)
2019-12-04 20:38:33 +05:30
module Types
class FakeType < BaseObject
argument :a_thing,
2021-03-11 19:13:27 +05:30
^^^^^^^^^^^^^^^^^^ Please add a `description` property.
2019-12-04 20:38:33 +05:30
GraphQL::STRING_TYPE,
null: false
end
end
TYPE
end
2021-02-22 17:27:13 +05:30
it 'adds an offense when description does not end in a period' do
2021-03-11 19:13:27 +05:30
expect_offense(<<~TYPE)
2019-12-04 20:38:33 +05:30
module Types
class FakeType < BaseObject
2021-02-22 17:27:13 +05:30
argument :a_thing,
2021-03-11 19:13:27 +05:30
^^^^^^^^^^^^^^^^^^ `description` strings must end with a `.`.
2021-02-22 17:27:13 +05:30
GraphQL::STRING_TYPE,
null: false,
description: 'Behold! A description'
end
end
TYPE
end
it 'does not add an offense when description is correct' do
expect_no_offenses(<<~TYPE.strip)
module Types
class FakeType < BaseObject
2019-12-04 20:38:33 +05:30
argument :a_thing,
2021-02-22 17:27:13 +05:30
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 `.`.
2019-12-04 20:38:33 +05:30
GraphQL::STRING_TYPE,
null: false,
description: 'Behold! A description'
end
end
TYPE
2021-02-22 17:27:13 +05:30
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
2019-12-04 20:38:33 +05:30
end
end
end