diff --git a/spec/ameba/cli/cmd_spec.cr b/spec/ameba/cli/cmd_spec.cr index 624d1ad9..a412c194 100644 --- a/spec/ameba/cli/cmd_spec.cr +++ b/spec/ameba/cli/cmd_spec.cr @@ -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 diff --git a/spec/ameba/config_spec.cr b/spec/ameba/config_spec.cr index d738310f..6287de05 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/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 diff --git a/spec/ameba_fixture.yml b/spec/ameba_fixture.yml new file mode 100644 index 00000000..c5394b90 --- /dev/null +++ b/spec/ameba_fixture.yml @@ -0,0 +1,2 @@ +Lint/ComparisonToBoolean: + Enabled: true diff --git a/src/ameba/cli/cmd.cr b/src/ameba/cli/cmd.cr index 3b06b905..d8ce4a7e 100644 --- a/src/ameba/cli/cmd.cr +++ b/src/ameba/cli/cmd.cr @@ -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 diff --git a/src/ameba/config.cr b/src/ameba/config.cr index 3d3a3c71..ad4f5dc6 100644 --- a/src/ameba/config.cr +++ b/src/ameba/config.cr @@ -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)