diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 9492b693..66136541 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -424,7 +424,16 @@ module Jekyll private def configure_theme self.theme = nil - self.theme = Jekyll::Theme.new(config["theme"]) if config["theme"] + return if config["theme"].nil? + + self.theme = + if config["theme"].is_a?(String) + Jekyll::Theme.new(config["theme"]) + else + Jekyll.logger.warn "Theme:", "value of 'theme' in config should be " \ + "String to use gem-based themes, but got #{config["theme"].class}" + nil + end end private diff --git a/test/test_site.rb b/test/test_site.rb index f09d94b9..57b06871 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -489,6 +489,34 @@ class TestSite < JekyllUnitTest end end + context "when setting theme" do + should "set no theme if config is not set" do + expect($stderr).not_to receive(:puts) + expect($stdout).not_to receive(:puts) + site = fixture_site({ "theme" => nil }) + assert_nil site.theme + end + + should "set no theme if config is a hash" do + output = capture_output do + site = fixture_site({ "theme" => {} }) + assert_nil site.theme + end + expected_msg = "Theme: value of 'theme' in config should be String " \ + "to use gem-based themes, but got Hash\n" + assert output.end_with?(expected_msg), + "Expected #{output.inspect} to end with #{expected_msg.inspect}" + end + + should "set a theme if the config is a string" do + expect($stderr).not_to receive(:puts) + expect($stdout).not_to receive(:puts) + site = fixture_site({ "theme" => "test-theme" }) + assert_instance_of Jekyll::Theme, site.theme + assert_equal "test-theme", site.theme.name + end + end + context "with liquid profiling" do setup do @site = Site.new(site_configuration("profile" => true))