summaryrefslogtreecommitdiff
path: root/spec/bin/changelog_spec.rb
blob: 8c8bc1b0f1c56511565d63afce844a568d1ec96f (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'spec_helper'

load File.expand_path('../../bin/changelog', __dir__)

describe 'bin/changelog' do
  describe ChangelogOptionParser do
    it 'parses --ammend' do
      options = described_class.parse(%w[foo bar --amend])

      expect(options.amend).to eq true
    end

    it 'parses --force' do
      options = described_class.parse(%w[foo --force bar])

      expect(options.force).to eq true
    end

    it 'parses -f' do
      options = described_class.parse(%w[foo -f bar])

      expect(options.force).to eq true
    end

    it 'parses --merge-request' do
      options = described_class.parse(%w[foo --merge-request 1234 bar])

      expect(options.merge_request).to eq 1234
    end

    it 'parses -m' do
      options = described_class.parse(%w[foo -m 4321 bar])

      expect(options.merge_request).to eq 4321
    end

    it 'parses --dry-run' do
      options = described_class.parse(%w[foo --dry-run bar])

      expect(options.dry_run).to eq true
    end

    it 'parses -n' do
      options = described_class.parse(%w[foo -n bar])

      expect(options.dry_run).to eq true
    end

    it 'parses --git-username' do
      allow(described_class).to receive(:git_user_name).and_return('Jane Doe')
      options = described_class.parse(%w[foo --git-username bar])

      expect(options.author).to eq 'Jane Doe'
    end

    it 'parses -u' do
      allow(described_class).to receive(:git_user_name).and_return('John Smith')
      options = described_class.parse(%w[foo -u bar])

      expect(options.author).to eq 'John Smith'
    end

    it 'parses -h' do
      expect do
        $stdout = StringIO.new

        described_class.parse(%w[foo -h bar])
      end.to raise_error(SystemExit)
    end

    it 'assigns title' do
      options = described_class.parse(%W[foo -m 1 bar\n -u baz\r\n --amend])

      expect(options.title).to eq 'foo bar baz'
    end
  end
end