diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-10-29 19:10:47 +0100 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-10-31 14:56:20 +0000 |
commit | 5acb3230efce11148c55dce9a53cd2a85e7d120a (patch) | |
tree | af8f1eb02e52159f9a6d91ce7a67ecad3a003d72 | |
parent | 23312b484f14c4843c782fd195a690e5e288af11 (diff) | |
download | gitlab-ce-5acb3230efce11148c55dce9a53cd2a85e7d120a.tar.gz |
Add specs for ChangelogOptionParser in bin/changelogrs-bin-changelog
-rwxr-xr-x | bin/changelog | 3 | ||||
-rw-r--r-- | spec/bin/changelog_spec.rb | 65 |
2 files changed, 67 insertions, 1 deletions
diff --git a/bin/changelog b/bin/changelog index 2b08e3e4c2a..a0d1ad2d730 100755 --- a/bin/changelog +++ b/bin/changelog @@ -42,7 +42,7 @@ class ChangelogOptionParser end opts.on('-h', '--help', 'Print help message') do - puts opts + $stdout.puts opts exit end end @@ -72,6 +72,7 @@ class ChangelogEntry $stdout.puts "\e[32mcreate\e[0m #{file_path}" $stdout.puts contents + unless options.dry_run write amend_commit if options.amend diff --git a/spec/bin/changelog_spec.rb b/spec/bin/changelog_spec.rb new file mode 100644 index 00000000000..da167dc570f --- /dev/null +++ b/spec/bin/changelog_spec.rb @@ -0,0 +1,65 @@ +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 --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 |