debian-mirror-gitlab/spec/bin/changelog_spec.rb

112 lines
3 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
load File.expand_path('../../bin/changelog', __dir__)
describe 'bin/changelog' do
2018-11-18 11:00:15 +05:30
let(:options) { OpenStruct.new(title: 'Test title', type: 'fixed', dry_run: true) }
describe ChangelogEntry do
it 'truncates the file path' do
entry = described_class.new(options)
allow(entry).to receive(:ee?).and_return(false)
allow(entry).to receive(:branch_name).and_return('long-branch-' * 100)
file_path = entry.send(:file_path)
expect(file_path.length).to eq(140)
end
end
2017-08-17 22:00:37 +05:30
describe ChangelogOptionParser do
2018-03-17 18:26:18 +05:30
describe '.parse' do
it 'parses --amend' do
options = described_class.parse(%w[foo bar --amend])
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(options.amend).to eq true
end
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
it 'parses --force and -f' do
%w[--force -f].each do |flag|
options = described_class.parse(%W[foo #{flag} bar])
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(options.force).to eq true
end
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
it 'parses --merge-request and -m' do
%w[--merge-request -m].each do |flag|
options = described_class.parse(%W[foo #{flag} 1234 bar])
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(options.merge_request).to eq 1234
end
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
it 'parses --dry-run and -n' do
%w[--dry-run -n].each do |flag|
options = described_class.parse(%W[foo #{flag} bar])
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(options.dry_run).to eq true
end
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
it 'parses --git-username and -u' do
allow(described_class).to receive(:git_user_name).and_return('Jane Doe')
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
%w[--git-username -u].each do |flag|
options = described_class.parse(%W[foo #{flag} bar])
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(options.author).to eq 'Jane Doe'
end
end
it 'parses --type and -t' do
%w[--type -t].each do |flag|
options = described_class.parse(%W[foo #{flag} security])
expect(options.type).to eq 'security'
end
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
it 'parses -h' do
expect do
expect { described_class.parse(%w[foo -h bar]) }.to output.to_stdout
2018-11-08 19:23:39 +05:30
end.to raise_error(ChangelogHelpers::Done)
2018-03-17 18:26:18 +05:30
end
it 'assigns title' do
2018-11-08 19:23:39 +05:30
options = described_class.parse(%W[foo -m 1 bar\n baz\r\n --amend])
2018-03-17 18:26:18 +05:30
expect(options.title).to eq 'foo bar baz'
end
2017-08-17 22:00:37 +05:30
end
2019-03-02 22:35:43 +05:30
describe '.read_type' do
2018-03-17 18:26:18 +05:30
let(:type) { '1' }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
it 'reads type from $stdin' do
expect($stdin).to receive(:getc).and_return(type)
expect do
expect(described_class.read_type).to eq('added')
end.to output.to_stdout
end
context 'invalid type given' do
let(:type) { '99' }
it 'shows error message and exits the program' do
allow($stdin).to receive(:getc).and_return(type)
2018-11-20 20:47:30 +05:30
2018-03-17 18:26:18 +05:30
expect do
2018-11-08 19:23:39 +05:30
expect { described_class.read_type }.to raise_error(
ChangelogHelpers::Abort,
'Invalid category index, please select an index between 1 and 8'
)
2018-03-17 18:26:18 +05:30
end.to output.to_stdout
end
end
2017-08-17 22:00:37 +05:30
end
end
end