Site#configure_theme: don't do anything if theme config is unset; TEST

This commit is contained in:
Parker Moore 2016-08-30 12:17:24 -07:00
parent 4420c3b2af
commit 2b15b0b325
No known key found for this signature in database
GPG Key ID: 193CDEBA72063C58
2 changed files with 30 additions and 1 deletions

View File

@ -423,11 +423,14 @@ module Jekyll
private
def configure_theme
self.theme = nil
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 "
Jekyll.logger.warn "Theme:", "value of 'theme' in config should be " \
"String to use gem-based themes, but got #{config["theme"].class}"
nil
end

View File

@ -489,6 +489,32 @@ 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))