2016-10-29 14:10:47 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
load File.expand_path('../../bin/changelog', __dir__)
|
|
|
|
|
|
|
|
describe 'bin/changelog' do
|
|
|
|
describe ChangelogOptionParser do
|
2017-05-20 16:49:55 -04:00
|
|
|
describe '.parse' do
|
|
|
|
it 'parses --amend' do
|
|
|
|
options = described_class.parse(%w[foo bar --amend])
|
2016-10-29 14:10:47 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
expect(options.amend).to eq true
|
|
|
|
end
|
2016-10-29 14:10:47 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
it 'parses --force and -f' do
|
|
|
|
%w[--force -f].each do |flag|
|
|
|
|
options = described_class.parse(%W[foo #{flag} bar])
|
2016-11-02 18:15:20 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
expect(options.force).to eq true
|
|
|
|
end
|
2016-11-02 18:21:12 -04:00
|
|
|
end
|
2016-11-02 18:15:20 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
it 'parses --merge-request and -m' do
|
|
|
|
%w[--merge-request -m].each do |flag|
|
|
|
|
options = described_class.parse(%W[foo #{flag} 1234 bar])
|
2016-11-02 18:15:20 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
expect(options.merge_request).to eq 1234
|
|
|
|
end
|
2016-11-02 18:21:12 -04:00
|
|
|
end
|
2016-11-02 18:15:20 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
it 'parses --dry-run and -n' do
|
|
|
|
%w[--dry-run -n].each do |flag|
|
|
|
|
options = described_class.parse(%W[foo #{flag} bar])
|
2016-10-29 14:10:47 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
expect(options.dry_run).to eq true
|
|
|
|
end
|
2016-11-02 18:21:12 -04:00
|
|
|
end
|
2016-10-29 14:10:47 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
it 'parses --git-username and -u' do
|
|
|
|
allow(described_class).to receive(:git_user_name).and_return('Jane Doe')
|
2016-10-29 14:10:47 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
%w[--git-username -u].each do |flag|
|
|
|
|
options = described_class.parse(%W[foo #{flag} bar])
|
2016-10-29 14:10:47 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
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
|
2016-11-02 18:21:12 -04:00
|
|
|
end
|
2016-10-29 14:10:47 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
it 'parses -h' do
|
|
|
|
expect do
|
|
|
|
expect { described_class.parse(%w[foo -h bar]) }.to output.to_stdout
|
|
|
|
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
|
2016-10-29 14:10:47 -04:00
|
|
|
end
|
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
describe '.read_type' do
|
|
|
|
let(:type) { '1' }
|
2016-10-29 14:10:47 -04:00
|
|
|
|
2017-05-20 16:49:55 -04:00
|
|
|
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)
|
|
|
|
expect do
|
|
|
|
expect do
|
2017-08-10 19:22:59 -04:00
|
|
|
expect { described_class.read_type }.to raise_error(SystemExit)
|
2017-05-20 16:49:55 -04:00
|
|
|
end.to output("Invalid category index, please select an index between 1 and 7\n").to_stderr
|
|
|
|
end.to output.to_stdout
|
|
|
|
end
|
|
|
|
end
|
2016-10-29 14:10:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|