Permalink
Browse files

--config option tests added

  • Loading branch information...
bfontaine committed May 25, 2012
1 parent 8672f1f commit 39d32c3345e241a7ac92c6233e2d5c2d86386c90
Showing with 40 additions and 0 deletions.
  1. +40 −0 test/test_configuration.rb
View
@@ -1,6 +1,7 @@
require 'helper'
class TestConfiguration < Test::Unit::TestCase
+
context "loading configuration" do
setup do
@path = File.join(Dir.pwd, '_config.yml')
@@ -26,4 +27,43 @@ class TestConfiguration < Test::Unit::TestCase
assert_equal Jekyll::DEFAULTS, Jekyll.configuration({})
end
end
+
+ context "loading configuration from a non-existent given file" do
+ setup do
+ @path = File.join(Dir.pwd, 'bad.yml')
+ end
+
+ should "fire warning if given file does not exist" 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({'config_file'=>'bad.yml'})
+ end
+ end
+
+ context "loading configuration from an existent given file" do
+ setup do
+ @path = File.join(Dir.pwd, '_myconfig.yml')
+ end
+
+ should "load configuration as hash" do
+ mock(YAML).load_file(@path) { { 'foo' => 'bar' } }
+ mock($stdout).puts("Configuration from #{@path}")
+ assert_equal Jekyll::DEFAULTS.merge({'config_file'=>'_myconfig.yml', 'foo'=>'bar'}),
+ Jekyll.configuration({'config_file'=>'_myconfig.yml'})
+ end
+ end
+
+ context "loading configuration from a bad given file" do
+ setup do
+ @path = File.join(Dir.pwd, '_array_config.yml')
+ end
+
+ should "fire warning with bad config" do
+ mock(YAML).load_file(@path) { ['foo', 'bar'] }
+ mock($stderr).puts("WARNING: Could not read configuration. Using defaults (and options).")
+ mock($stderr).puts("\tInvalid configuration - #{@path}")
+ assert_equal Jekyll::DEFAULTS, Jekyll.configuration({'config_file'=>'_array_config.yml'})
+ end
+ end
end

0 comments on commit 39d32c3

Please sign in to comment.