Validating the configuration loads properly and is a hash, based on jrk's implementation. Closes #22.
This commit is contained in:
parent
86b1450234
commit
486ae25fc1
|
@ -11,6 +11,6 @@ JEKYLL_PATH = File.join(ENV['PWD'], 'bin', 'jekyll')
|
|||
|
||||
def run_jekyll(opts = {})
|
||||
command = JEKYLL_PATH
|
||||
command << " >> /dev/null" if opts[:debug].nil?
|
||||
command << " >> /dev/null 2>&1" if opts[:debug].nil?
|
||||
system command
|
||||
end
|
||||
|
|
|
@ -63,14 +63,15 @@ module Jekyll
|
|||
source = override['source'] || Jekyll::DEFAULTS['source']
|
||||
|
||||
# Get configuration from <source>/_config.yml
|
||||
config = {}
|
||||
config_file = File.join(source, '_config.yml')
|
||||
begin
|
||||
config = YAML.load_file(config_file)
|
||||
puts "Configuration from #{config_file}"
|
||||
raise "Invalid configuration - #{config_file}" if !config.is_a?(Hash)
|
||||
STDOUT.puts "Configuration from #{config_file}"
|
||||
rescue => err
|
||||
puts "WARNING: Could not read configuration. Using defaults (and options)."
|
||||
puts "\t" + err
|
||||
STDERR.puts "WARNING: Could not read configuration. Using defaults (and options)."
|
||||
STDERR.puts "\t" + err
|
||||
config = {}
|
||||
end
|
||||
|
||||
# Merge DEFAULTS < _config.yml < override
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
require File.dirname(__FILE__) + '/helper'
|
||||
|
||||
class TestConfiguration < Test::Unit::TestCase
|
||||
context "loading configuration" do
|
||||
setup do
|
||||
@path = './_config.yml'
|
||||
end
|
||||
|
||||
should "fire warning with no _config.yml" do
|
||||
mock(YAML).load_file(@path) { raise "No such file or directory - #{@path}" }
|
||||
mock(STDERR).puts("WARNING: Could not read configuration. Using defaults (and options).")
|
||||
mock(STDERR).puts("\tNo such file or directory - #{@path}")
|
||||
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
|
||||
end
|
||||
|
||||
should "load configuration as hash" do
|
||||
mock(YAML).load_file(@path) { Hash.new }
|
||||
mock(STDOUT).puts("Configuration from #{@path}")
|
||||
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
|
||||
end
|
||||
|
||||
should "fire warning with bad config" do
|
||||
mock(YAML).load_file(@path) { Array.new }
|
||||
mock(STDERR).puts("WARNING: Could not read configuration. Using defaults (and options).")
|
||||
mock(STDERR).puts("\tInvalid configuration - #{@path}")
|
||||
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue