BigW Consortium Gitlab

changelog_spec.rb 1.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
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

13 14 15
    it 'parses --force and -f' do
      %w[--force -f].each do |flag|
        options = described_class.parse(%W[foo #{flag} bar])
16

17 18
        expect(options.force).to eq true
      end
19 20
    end

21 22 23
    it 'parses --merge-request and -m' do
      %w[--merge-request -m].each do |flag|
        options = described_class.parse(%W[foo #{flag} 1234 bar])
24

25 26
        expect(options.merge_request).to eq 1234
      end
27 28
    end

29 30 31
    it 'parses --dry-run and -n' do
      %w[--dry-run -n].each do |flag|
        options = described_class.parse(%W[foo #{flag} bar])
32

33 34
        expect(options.dry_run).to eq true
      end
35 36
    end

37
    it 'parses --git-username and -u' do
38 39
      allow(described_class).to receive(:git_user_name).and_return('Jane Doe')

40 41
      %w[--git-username -u].each do |flag|
        options = described_class.parse(%W[foo #{flag} bar])
42

43 44
        expect(options.author).to eq 'Jane Doe'
      end
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    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