mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Merge branch 'master' into 388-raise-on-invalid-file-path
This commit is contained in:
commit
07aebfc84a
2 changed files with 10 additions and 3 deletions
|
@ -2,7 +2,7 @@ require "../spec_helper"
|
||||||
|
|
||||||
module Ameba
|
module Ameba
|
||||||
describe Config do
|
describe Config do
|
||||||
config_sample = "config/ameba.yml"
|
config_sample = "spec/fixtures/config.yml"
|
||||||
|
|
||||||
it "should have a list of available formatters" do
|
it "should have a list of available formatters" do
|
||||||
Config::AVAILABLE_FORMATTERS.should_not be_nil
|
Config::AVAILABLE_FORMATTERS.should_not be_nil
|
||||||
|
@ -84,6 +84,12 @@ module Ameba
|
||||||
config.formatter.should_not be_nil
|
config.formatter.should_not be_nil
|
||||||
end
|
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
|
it "loads default config" do
|
||||||
config = Config.load
|
config = Config.load
|
||||||
config.should_not be_nil
|
config.should_not be_nil
|
||||||
|
|
|
@ -115,12 +115,13 @@ class Ameba::Config
|
||||||
end
|
end
|
||||||
Config.new YAML.parse(content)
|
Config.new YAML.parse(content)
|
||||||
rescue e
|
rescue e
|
||||||
raise "Config file is invalid: #{e.message}"
|
raise "Unable to load config file: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
protected def self.read_config(path = nil)
|
protected def self.read_config(path = nil)
|
||||||
if path
|
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
|
end
|
||||||
each_config_path do |config_path|
|
each_config_path do |config_path|
|
||||||
return File.read(config_path) if File.exists?(config_path)
|
return File.read(config_path) if File.exists?(config_path)
|
||||||
|
|
Loading…
Reference in a new issue