From fb3075d7e5105cb491bebb8de2793d4a3939154c Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 16 Feb 2018 13:56:41 -0800 Subject: [PATCH] Raise error instead of unhelpful behavior for --since-tag or --due-tag Fixes #604 The --since-tag and --due-tag arguments exist to specify tags between which the changelog should be generated. Prior to this change if these tags do not exist then GCG continues to generate the entire changelog which is not what the user requested. This change causes an error informing the user that their specified tags do not exist so their request could not be completed. Other arguments with similar behavior such as --exclude-tags and --exclude-tags-regex may continue to only give a warning in case the user made a mistake, but should not error as nonexistent tags are trivially excluded. --- .../generator/generator_tags.rb | 4 ++-- spec/unit/generator/generator_tags_spec.rb | 24 ++++--------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index d8f4534ab..7568a1790 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -135,7 +135,7 @@ def filter_since_tag(all_tags) [] end else - Helper.log.warn "Warning: can't find tag #{tag}, specified with --since-tag option." + raise ChangelogGeneratorError, "Error: can't find tag #{tag}, specified with --since-tag option." end end filtered_tags @@ -155,7 +155,7 @@ def filter_due_tag(all_tags) [] end else - Helper.log.warn "Warning: can't find tag #{tag}, specified with --due-tag option." + raise ChangelogGeneratorError, "Error: can't find tag #{tag}, specified with --due-tag option." end end filtered_tags diff --git a/spec/unit/generator/generator_tags_spec.rb b/spec/unit/generator/generator_tags_spec.rb index d9dc6b46c..515da2302 100644 --- a/spec/unit/generator/generator_tags_spec.rb +++ b/spec/unit/generator/generator_tags_spec.rb @@ -191,24 +191,16 @@ def tags_from_strings(tags_strings) context "with invalid since tag" do let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "Invalid tag") } - it { is_expected.to be_a Array } - it { is_expected.to match_array(tags_from_strings(%w[1 2 3])) } + it { expect { subject }.to raise_error(GitHubChangelogGenerator::ChangelogGeneratorError) } end end context "with empty array" do subject { generator.filter_since_tag(tags_from_strings(%w[])) } - context "with valid since tag" do - let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") } - it { is_expected.to be_a Array } - it { is_expected.to match_array(tags_from_strings(%w[])) } - end - context "with invalid since tag" do let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "Invalid tag") } - it { is_expected.to be_a Array } - it { is_expected.to match_array(tags_from_strings(%w[])) } + it { expect { subject }.to raise_error(GitHubChangelogGenerator::ChangelogGeneratorError) } end end end @@ -225,24 +217,16 @@ def tags_from_strings(tags_strings) context "with invalid due tag" do let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "Invalid tag") } - it { is_expected.to be_a Array } - it { is_expected.to match_array(tags_from_strings(%w[1 2 3])) } + it { expect { subject }.to raise_error(GitHubChangelogGenerator::ChangelogGeneratorError) } end end context "with empty array" do subject { generator.filter_due_tag(tags_from_strings(%w[])) } - context "with valid due tag" do - let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "2") } - it { is_expected.to be_a Array } - it { is_expected.to match_array(tags_from_strings(%w[])) } - end - context "with invalid due tag" do let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "Invalid tag") } - it { is_expected.to be_a Array } - it { is_expected.to match_array(tags_from_strings(%w[])) } + it { expect { subject }.to raise_error(GitHubChangelogGenerator::ChangelogGeneratorError) } end end end