Reword error when file doesn't exist

Applied suggestion from PR

Co-authored-by: Vitalii Elenhaupt <3624712+veelenga@users.noreply.github.com>
This commit is contained in:
Stuart Frost 2023-07-25 08:43:08 +01:00 committed by Stuart Frost
parent 5f878fb40f
commit d9b2d69055
2 changed files with 3 additions and 2 deletions

View File

@ -85,7 +85,7 @@ module Ameba
end
it "raises when custom config file doesn't exist" do
expect_raises(Exception, "Config file is invalid: Unable to find config file foo.yml") do
expect_raises(Exception, "Config file is invalid: Config file does not exist foo.yml") do
Config.load "foo.yml"
end
end

View File

@ -120,7 +120,8 @@ class Ameba::Config
protected def self.read_config(path = nil)
if path
return File.exists?(path) ? File.read(path) : raise("Unable to find config file #{path}")
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)