2016-09-22 17:04:35 +00:00
|
|
|
# frozen_string_literal: true
|
2015-09-15 18:38:41 +00:00
|
|
|
describe GitHubChangelogGenerator::ParserFile do
|
|
|
|
describe ".github_changelog_generator" do
|
2016-03-19 15:54:13 +00:00
|
|
|
let(:options) { {} }
|
|
|
|
|
|
|
|
context "when the well-known default file does not exist" do
|
2016-03-19 14:22:45 +00:00
|
|
|
let(:parser) { GitHubChangelogGenerator::ParserFile.new(options) }
|
|
|
|
subject { parser.parse! }
|
2015-09-15 18:38:41 +00:00
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when file is empty" do
|
2016-03-19 14:22:45 +00:00
|
|
|
let(:parser) { GitHubChangelogGenerator::ParserFile.new(options, StringIO.new("")) }
|
2015-09-22 19:45:16 +00:00
|
|
|
|
|
|
|
it "does not change the options" do
|
2016-03-19 14:22:45 +00:00
|
|
|
expect { parser.parse! }.to_not change { options }
|
2015-09-22 19:45:16 +00:00
|
|
|
end
|
2015-09-15 18:38:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when file is incorrect" do
|
2015-09-22 19:45:16 +00:00
|
|
|
let(:options_before_change) { options.dup }
|
2016-03-19 14:20:48 +00:00
|
|
|
let(:file) { StringIO.new("unreleased_label=staging\nunreleased: false") }
|
2016-03-19 14:22:45 +00:00
|
|
|
let(:parser) do
|
2016-03-19 12:59:58 +00:00
|
|
|
GitHubChangelogGenerator::ParserFile.new(options, file)
|
|
|
|
end
|
2016-03-19 14:22:45 +00:00
|
|
|
it { expect { parser.parse! }.to raise_error(/line #2/) }
|
2015-09-15 18:38:41 +00:00
|
|
|
end
|
|
|
|
|
2016-03-19 16:12:30 +00:00
|
|
|
context "allows empty lines and comments with semi-colon or pound sign" do
|
|
|
|
let(:file) { StringIO.new("\n \n# Comment on first line\nunreleased_label=staging\n; Comment on third line\nunreleased=false") }
|
2016-03-19 15:42:36 +00:00
|
|
|
let(:parser) do
|
2016-03-19 15:54:13 +00:00
|
|
|
GitHubChangelogGenerator::ParserFile.new(options, file)
|
2016-03-19 15:42:36 +00:00
|
|
|
end
|
|
|
|
it { expect { parser.parse! }.not_to raise_error }
|
|
|
|
end
|
|
|
|
|
2015-09-15 18:38:41 +00:00
|
|
|
context "when override default values" do
|
2015-10-21 22:09:25 +00:00
|
|
|
let(:default_options) { GitHubChangelogGenerator::Parser.default_options }
|
2016-03-19 12:59:58 +00:00
|
|
|
let(:options) { {}.merge(default_options) }
|
2015-09-22 19:45:16 +00:00
|
|
|
let(:options_before_change) { options.dup }
|
2016-03-19 12:59:58 +00:00
|
|
|
let(:file) { StringIO.new("unreleased_label=staging\nunreleased=false\nheader==== Changelog ===") }
|
2016-03-19 14:22:45 +00:00
|
|
|
let(:parser) { GitHubChangelogGenerator::ParserFile.new(options, file) }
|
2015-09-22 19:45:16 +00:00
|
|
|
|
|
|
|
it "changes the options" do
|
2016-03-19 14:22:45 +00:00
|
|
|
expect { parser.parse! }.to change { options }
|
2015-09-22 19:45:16 +00:00
|
|
|
.from(options_before_change)
|
|
|
|
.to(options_before_change.merge(unreleased_label: "staging",
|
|
|
|
unreleased: false,
|
|
|
|
header: "=== Changelog ==="))
|
|
|
|
end
|
2016-02-23 21:24:10 +00:00
|
|
|
|
2016-07-20 15:32:08 +00:00
|
|
|
context "turns exclude-labels into an Array", bug: "#327" do
|
2016-03-19 12:59:58 +00:00
|
|
|
let(:file) do
|
|
|
|
StringIO.new(<<EOF
|
|
|
|
exclude-labels=73a91042-da6f-11e5-9335-1040f38d7f90,7adf83b4-da6f-11e5-ae18-1040f38d7f90
|
|
|
|
header_label=# My changelog
|
|
|
|
EOF
|
|
|
|
)
|
2016-02-24 13:02:56 +00:00
|
|
|
end
|
2016-02-23 21:24:10 +00:00
|
|
|
it "reads exclude_labels into an Array" do
|
2016-03-19 14:22:45 +00:00
|
|
|
expect { parser.parse! }.to change { options[:exclude_labels] }
|
2016-03-19 12:59:58 +00:00
|
|
|
.from(default_options[:exclude_labels])
|
2016-02-24 13:02:56 +00:00
|
|
|
.to(["73a91042-da6f-11e5-9335-1040f38d7f90", "7adf83b4-da6f-11e5-ae18-1040f38d7f90"])
|
2016-02-23 21:24:10 +00:00
|
|
|
end
|
2016-03-17 20:38:28 +00:00
|
|
|
|
|
|
|
it "translates given header_label into the :header option" do
|
2016-03-19 14:22:45 +00:00
|
|
|
expect { parser.parse! }.to change { options[:header] }
|
2016-03-19 12:59:58 +00:00
|
|
|
.from(default_options[:header])
|
2016-03-17 20:38:28 +00:00
|
|
|
.to("# My changelog")
|
|
|
|
end
|
2016-02-23 21:24:10 +00:00
|
|
|
end
|
2015-09-15 18:38:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|