Merge pull request #296 from olleolleolle/feature/introduce-parsererror-class

Introduce ParserError exception class
This commit is contained in:
Petr Korolev 2015-10-22 15:25:54 +03:00
commit 8f78bb0cc6
2 changed files with 4 additions and 2 deletions

View File

@ -1,4 +1,6 @@
module GitHubChangelogGenerator module GitHubChangelogGenerator
ParserError = Class.new(StandardError)
class ParserFile class ParserFile
def initialize(options) def initialize(options)
@options = options @options = options
@ -22,7 +24,7 @@ module GitHubChangelogGenerator
value = false if value =~ (/^(false|f|no|n|0)$/i) value = false if value =~ (/^(false|f|no|n|0)$/i)
@options[key_sym] = value @options[key_sym] = value
rescue rescue
raise "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\"" raise ParserError, "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
end end
# Returns a the setting as a symbol and its string value sans newlines. # Returns a the setting as a symbol and its string value sans newlines.

View File

@ -20,7 +20,7 @@ describe GitHubChangelogGenerator::ParserFile do
let(:options) { { params_file: "spec/files/github_changelog_params_incorrect" } } let(:options) { { params_file: "spec/files/github_changelog_params_incorrect" } }
let(:options_before_change) { options.dup } let(:options_before_change) { options.dup }
let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) } let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }
it { expect { parse.parse! }.to raise_error } it { expect { parse.parse! }.to raise_error(GitHubChangelogGenerator::ParserError) }
end end
context "when override default values" do context "when override default values" do