mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Move missing config file check into Ameba::Config
This commit is contained in:
parent
01a943d0d6
commit
5f878fb40f
5 changed files with 12 additions and 12 deletions
|
@ -20,14 +20,8 @@ module Ameba::Cli
|
|||
|
||||
%w(-c --config).each do |f|
|
||||
it "accepts #{f} flag" do
|
||||
c = Cli.parse_args [f, "shard.yml"]
|
||||
c.config.should eq Path["shard.yml"]
|
||||
end
|
||||
|
||||
it "raises when config file doesn't exist" do
|
||||
expect_raises(ArgumentError, "Unable to find config file foo.yml") do
|
||||
Cli.parse_args [f, "foo.yml"]
|
||||
end
|
||||
c = Cli.parse_args [f, "config.yml"]
|
||||
c.config.should eq Path["config.yml"]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ require "../spec_helper"
|
|||
|
||||
module Ameba
|
||||
describe Config do
|
||||
config_sample = "config/ameba.yml"
|
||||
config_sample = "spec/ameba_fixture.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, "Config file is invalid: Unable to find config file foo.yml") do
|
||||
Config.load "foo.yml"
|
||||
end
|
||||
end
|
||||
|
||||
it "loads default config" do
|
||||
config = Config.load
|
||||
config.should_not be_nil
|
||||
|
|
2
spec/ameba_fixture.yml
Normal file
2
spec/ameba_fixture.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
Lint/ComparisonToBoolean:
|
||||
Enabled: true
|
|
@ -77,8 +77,6 @@ module Ameba::Cli
|
|||
|
||||
parser.on("-c", "--config PATH",
|
||||
"Specify a configuration file") do |path|
|
||||
raise ArgumentError.new("Unable to find config file #{path}") if !File.exists?(path) && !opts.skip_reading_config?
|
||||
|
||||
opts.config = Path[path] unless path.empty?
|
||||
end
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ class Ameba::Config
|
|||
|
||||
protected def self.read_config(path = nil)
|
||||
if path
|
||||
return File.exists?(path) ? File.read(path) : nil
|
||||
return File.exists?(path) ? File.read(path) : raise("Unable to find config file #{path}")
|
||||
end
|
||||
each_config_path do |config_path|
|
||||
return File.read(config_path) if File.exists?(config_path)
|
||||
|
|
Loading…
Reference in a new issue