Permalink
Browse files

Validating the configuration loads properly and is a hash, based on j…

…rk's implementation. Closes #22.
  • Loading branch information...
1 parent 86b1450 commit 486ae25fc18660fe8bcf7f965cb56b34d0abddfc @qrush qrush committed Jun 1, 2009
Showing with 35 additions and 5 deletions.
  1. +1 −1 features/support/env.rb
  2. +5 −4 lib/jekyll.rb
  3. +29 −0 test/test_configuration.rb
View
@@ -11,6 +11,6 @@
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
View
@@ -63,14 +63,15 @@ def self.configuration(override)
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
View
@@ -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

0 comments on commit 486ae25

Please sign in to comment.