diff --git a/spec/ameba/config_spec.cr b/spec/ameba/config_spec.cr index d738310f..1c1d10b2 100644 --- a/spec/ameba/config_spec.cr +++ b/spec/ameba/config_spec.cr @@ -2,7 +2,7 @@ require "../spec_helper" module Ameba describe Config do - config_sample = "config/ameba.yml" + config_sample = "spec/fixtures/config.yml" it "should have a list of available formatters" do Config::AVAILABLE_FORMATTERS.should_not be_nil @@ -84,6 +84,12 @@ module Ameba config.formatter.should_not be_nil end + it "raises when custom config file doesn't exist" do + expect_raises(Exception, "Unable to load config file: Config file does not exist foo.yml") do + Config.load "foo.yml" + end + end + it "loads default config" do config = Config.load config.should_not be_nil diff --git a/src/ameba/config.cr b/src/ameba/config.cr index 3d3a3c71..821fa065 100644 --- a/src/ameba/config.cr +++ b/src/ameba/config.cr @@ -115,12 +115,13 @@ class Ameba::Config end Config.new YAML.parse(content) rescue e - raise "Config file is invalid: #{e.message}" + raise "Unable to load config file: #{e.message}" end protected def self.read_config(path = nil) if path - return File.exists?(path) ? File.read(path) : nil + raise ArgumentError.new("Config file does not exist #{path}") unless File.exists?(path) + return File.read(path) end each_config_path do |config_path| return File.read(config_path) if File.exists?(config_path)