mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Merge pull request #393 from stufro/362-raise-on-invalid-config-file-path
Raise error when passed invalid config file path
This commit is contained in:
		
						commit
						8ef588dc6d
					
				
					 3 changed files with 12 additions and 3 deletions
				
			
		|  | @ -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 | ||||
|  |  | |||
							
								
								
									
										2
									
								
								spec/fixtures/config.yml
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								spec/fixtures/config.yml
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| Lint/ComparisonToBoolean: | ||||
|   Enabled: true | ||||
|  | @ -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) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue