Welcome to mirror list, hosted at ThFree Co, Russian Federation.

enum_names_spec.rb « graphql « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f45df068381f0fd4570d8e7492b5f01f383a7883 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true

require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/graphql/enum_names'

RSpec.describe RuboCop::Cop::Graphql::EnumNames do
  describe 'class name' do
    it 'adds an offense when class name does not end with `Enum`' do
      expect_offense(<<~ENUM)
        module Types
          class Fake < BaseEnum
                ^^^^ #{described_class::CLASS_NAME_SUFFIX_MSG}
            graphql_name 'Fake'
          end
        end
      ENUM
    end
  end

  describe 'graphql_name' do
    it 'adds an offense when `graphql_name` is not set' do
      expect_offense(<<~ENUM)
        module Types
          class FakeEnum < BaseEnum
          ^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::GRAPHQL_NAME_MISSING_MSG}
          end
        end
      ENUM
    end

    it 'adds no offense when `declarative_enum` is used' do
      expect_no_offenses(<<~ENUM)
        module Types
          class FakeEnum < BaseEnum
            declarative_enum ::FakeModule::FakeDeclarativeEnum
          end
        end
      ENUM
    end

    it 'adds an offense when `graphql_name` includes `enum`' do
      expect_offense(<<~ENUM)
        module Types
          class FakeEnum < BaseEnum
            graphql_name 'FakeEnum'
                         ^^^^^^^^^^ #{described_class::GRAPHQL_NAME_WITH_ENUM_MSG}
          end
        end
      ENUM
    end
  end
end