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

title_linting_spec.rb « danger « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b48d2c5e53d662da33932e34fa7254ef70c6c90e (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
53
54
55
56
# frozen_string_literal: true

require 'fast_spec_helper'
require 'rspec-parameterized'

require 'gitlab/danger/title_linting'

RSpec.describe Gitlab::Danger::TitleLinting do
  using RSpec::Parameterized::TableSyntax

  describe '#sanitize_mr_title' do
    where(:mr_title, :expected_mr_title) do
      '`My MR title`' | "\\`My MR title\\`"
      'WIP: My MR title' | 'My MR title'
      'Draft: My MR title' | 'My MR title'
      '(Draft) My MR title' | 'My MR title'
      '[Draft] My MR title' | 'My MR title'
      '[DRAFT] My MR title' | 'My MR title'
      'DRAFT: My MR title' | 'My MR title'
      'DRAFT: `My MR title`' | "\\`My MR title\\`"
    end

    with_them do
      subject { described_class.sanitize_mr_title(mr_title) }

      it { is_expected.to eq(expected_mr_title) }
    end
  end

  describe '#remove_draft_flag' do
    where(:mr_title, :expected_mr_title) do
      'WIP: My MR title' | 'My MR title'
      'Draft: My MR title' | 'My MR title'
      '(Draft) My MR title' | 'My MR title'
      '[Draft] My MR title' | 'My MR title'
      '[DRAFT] My MR title' | 'My MR title'
      'DRAFT: My MR title' | 'My MR title'
    end

    with_them do
      subject { described_class.remove_draft_flag(mr_title) }

      it { is_expected.to eq(expected_mr_title) }
    end
  end

  describe '#has_draft_flag?' do
    it 'returns true for a draft title' do
      expect(described_class.has_draft_flag?('Draft: My MR title')).to be true
    end

    it 'returns false for non draft title' do
      expect(described_class.has_draft_flag?('My MR title')).to be false
    end
  end
end