diff options
Diffstat (limited to 'spec/rubocop/cop/graphql/descriptions_spec.rb')
-rw-r--r-- | spec/rubocop/cop/graphql/descriptions_spec.rb | 118 |
1 files changed, 98 insertions, 20 deletions
diff --git a/spec/rubocop/cop/graphql/descriptions_spec.rb b/spec/rubocop/cop/graphql/descriptions_spec.rb index 9709a253bdc..84520a89b08 100644 --- a/spec/rubocop/cop/graphql/descriptions_spec.rb +++ b/spec/rubocop/cop/graphql/descriptions_spec.rb @@ -12,8 +12,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeType < BaseObject field :a_thing, - ^^^^^^^^^^^^^^^ Please add a `description` property. - GraphQL::STRING_TYPE, + ^^^^^^^^^^^^^^^ #{described_class::MSG_NO_DESCRIPTION} + GraphQL::Types::String, null: false end end @@ -25,10 +25,38 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeType < BaseObject field :a_thing, - ^^^^^^^^^^^^^^^ `description` strings must end with a `.`. - GraphQL::STRING_TYPE, + ^^^^^^^^^^^^^^^ #{described_class::MSG_NO_PERIOD} + GraphQL::Types::String, null: false, - description: 'A descriptive description' + description: 'Description of a thing' + end + end + TYPE + end + + it 'adds an offense when description begins with "A"' do + expect_offense(<<~TYPE) + module Types + class FakeType < BaseObject + field :a_thing, + ^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START} + GraphQL::Types::String, + null: false, + description: 'A description of the thing.' + end + end + TYPE + end + + it 'adds an offense when description begins with "The"' do + expect_offense(<<~TYPE) + module Types + class FakeType < BaseObject + field :a_thing, + ^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START} + GraphQL::Types::String, + null: false, + description: 'The description of the thing.' end end TYPE @@ -39,9 +67,9 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeType < BaseObject field :a_thing, - GraphQL::STRING_TYPE, + GraphQL::Types::String, null: false, - description: 'A descriptive description.' + description: 'Description of a thing.' end end TYPE @@ -64,8 +92,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeType < BaseObject argument :a_thing, - ^^^^^^^^^^^^^^^^^^ Please add a `description` property. - GraphQL::STRING_TYPE, + ^^^^^^^^^^^^^^^^^^ #{described_class::MSG_NO_DESCRIPTION} + GraphQL::Types::String, null: false end end @@ -77,8 +105,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeType < BaseObject argument :a_thing, - ^^^^^^^^^^^^^^^^^^ `description` strings must end with a `.`. - GraphQL::STRING_TYPE, + ^^^^^^^^^^^^^^^^^^ #{described_class::MSG_NO_PERIOD} + GraphQL::Types::String, null: false, description: 'Behold! A description' end @@ -86,12 +114,40 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do TYPE end + it 'adds an offense when description begins with "A"' do + expect_offense(<<~TYPE) + module Types + class FakeType < BaseObject + argument :a_thing, + ^^^^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START} + GraphQL::Types::String, + null: false, + description: 'A description.' + end + end + TYPE + end + + it 'adds an offense when description begins with "The"' do + expect_offense(<<~TYPE) + module Types + class FakeType < BaseObject + argument :a_thing, + ^^^^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START} + GraphQL::Types::String, + null: false, + description: 'The 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 argument :a_thing, - GraphQL::STRING_TYPE, + GraphQL::Types::String, null: false, description: 'Behold! A description.' end @@ -106,7 +162,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeEnum < BaseEnum value 'FOO', value: 'foo' - ^^^^^^^^^^^^^^^^^^^^^^^^^ Please add a `description` property. + ^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG_NO_DESCRIPTION} end end TYPE @@ -117,7 +173,29 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeEnum < BaseEnum value 'FOO', value: 'foo', description: 'bar' - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `description` strings must end with a `.`. + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG_NO_PERIOD} + end + end + TYPE + end + + it 'adds an offense when description begins with "The"' do + expect_offense(<<~TYPE.strip) + module Types + class FakeEnum < BaseEnum + value 'FOO', value: 'foo', description: 'The description.' + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START} + end + end + TYPE + end + + it 'adds an offense when description begins with "A"' do + expect_offense(<<~TYPE.strip) + module Types + class FakeEnum < BaseEnum + value 'FOO', value: 'foo', description: 'A description.' + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG_BAD_START} end end TYPE @@ -150,8 +228,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeType < BaseObject field :a_thing, - ^^^^^^^^^^^^^^^ `description` strings must end with a `.`. - GraphQL::STRING_TYPE, + ^^^^^^^^^^^^^^^ #{described_class::MSG_NO_PERIOD} + GraphQL::Types::String, null: false, description: 'Behold! A description' end @@ -162,7 +240,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeType < BaseObject field :a_thing, - GraphQL::STRING_TYPE, + GraphQL::Types::String, null: false, description: 'Behold! A description.' end @@ -175,8 +253,8 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeType < BaseObject field :a_thing, - ^^^^^^^^^^^^^^^ `description` strings must end with a `.`. - GraphQL::STRING_TYPE, + ^^^^^^^^^^^^^^^ #{described_class::MSG_NO_PERIOD} + GraphQL::Types::String, null: false, description: <<~DESC Behold! A description @@ -189,7 +267,7 @@ RSpec.describe RuboCop::Cop::Graphql::Descriptions do module Types class FakeType < BaseObject field :a_thing, - GraphQL::STRING_TYPE, + GraphQL::Types::String, null: false, description: <<~DESC Behold! A description. |