Merge pull request #4942 from pathawks/fp/configuration-from-permalink-fix

Merge pull request 4942
This commit is contained in:
jekyllbot 2016-05-25 15:42:05 -07:00
commit cf810a88fa
11 changed files with 260 additions and 107 deletions

View File

@ -98,18 +98,16 @@ module Jekyll
# list of option names and their defaults. # list of option names and their defaults.
# #
# Returns the final configuration Hash. # Returns the final configuration Hash.
def configuration(override = {}) def configuration(override = Hash.new)
config = Configuration[Configuration::DEFAULTS] config = Configuration.new
override = Configuration[override].stringify_keys
unless override.delete('skip_config_files') unless override.delete('skip_config_files')
config = config.read_config_files(config.config_files(override)) config = config.read_config_files(config.config_files(override))
end end
# Merge DEFAULTS < _config.yml < override # Merge DEFAULTS < _config.yml < override
config = Utils.deep_merge_hashes(config, override).stringify_keys Configuration.from(Utils.deep_merge_hashes(config, override)).tap do |config|
set_timezone(config['timezone']) if config['timezone'] set_timezone(config['timezone']) if config['timezone']
end
config
end end
# Public: Set the TZ environment variable to use the timezone specified # Public: Set the TZ environment variable to use the timezone specified

View File

@ -72,7 +72,24 @@ module Jekyll
'hard_wrap' => false, 'hard_wrap' => false,
'footnote_nr' => 1 'footnote_nr' => 1
} }
}] }.map { |k, v| [k, v.freeze] }].freeze
class << self
# Static: Produce a Configuration ready for use in a Site.
# It takes the input, fills in the defaults where values do not
# exist, and patches common issues including migrating options for
# backwards compatiblity. Except where a key or value is being fixed,
# the user configuration will override the defaults.
#
# user_config - a Hash or Configuration of overrides.
#
# Returns a Configuration filled with defaults and fixed for common
# problems and backwards-compatibility.
def from(user_config)
Utils.deep_merge_hashes(DEFAULTS, Configuration[user_config].stringify_keys).
fix_common_issues.add_default_collections
end
end
# Public: Turn all keys into string # Public: Turn all keys into string
# #
@ -169,6 +186,7 @@ module Jekyll
begin begin
files.each do |config_file| files.each do |config_file|
next if config_file.nil? or config_file.empty?
new_config = read_config_file(config_file) new_config = read_config_file(config_file)
configuration = Utils.deep_merge_hashes(configuration, new_config) configuration = Utils.deep_merge_hashes(configuration, new_config)
end end
@ -228,7 +246,6 @@ module Jekyll
end end
%w(include exclude).each do |option| %w(include exclude).each do |option|
config[option] ||= []
if config[option].is_a?(String) if config[option].is_a?(String)
Jekyll::Deprecator.deprecation_message "The '#{option}' configuration option" \ Jekyll::Deprecator.deprecation_message "The '#{option}' configuration option" \
" must now be specified as an array, but you specified" \ " must now be specified as an array, but you specified" \
@ -236,7 +253,7 @@ module Jekyll
" as a list of comma-separated values." " as a list of comma-separated values."
config[option] = csv_to_array(config[option]) config[option] = csv_to_array(config[option])
end end
config[option].map!(&:to_s) config[option].map!(&:to_s) if config[option]
end end
if (config['kramdown'] || {}).key?('use_coderay') if (config['kramdown'] || {}).key?('use_coderay')
@ -271,14 +288,22 @@ module Jekyll
def add_default_collections def add_default_collections
config = clone config = clone
# It defaults to `{}`, so this is only if someone sets it to null manually.
return config if config['collections'].nil? return config if config['collections'].nil?
# Ensure we have a hash.
if config['collections'].is_a?(Array) if config['collections'].is_a?(Array)
config['collections'] = Hash[config['collections'].map { |c| [c, {}] }] config['collections'] = Hash[config['collections'].map { |c| [c, {}] }]
end end
config['collections']['posts'] ||= {}
config['collections']['posts']['output'] = true config['collections'] = Utils.deep_merge_hashes(
config['collections']['posts']['permalink'] = style_to_permalink(config['permalink']) { 'posts' => {} }, config['collections']
).tap do |collections|
collections['posts']['output'] = true
if config['permalink']
collections['posts']['permalink'] ||= style_to_permalink(config['permalink'])
end
end
config config
end end

View File

@ -147,6 +147,12 @@ module Jekyll
keys.each(&block) keys.each(&block)
end end
def each(&block)
each_key.each do |key|
yield key, self[key]
end
end
def merge(other, &block) def merge(other, &block)
self.dup.tap do |me| self.dup.tap do |me|
if block.nil? if block.nil?

View File

@ -28,7 +28,7 @@ module Jekyll
end end
def collections def collections
@site_collections ||= @obj.collections.values.map(&:to_liquid) @site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
end end
private private

View File

@ -76,7 +76,7 @@ module Jekyll
# #
# Returns an Array of plugin search paths # Returns an Array of plugin search paths
def plugins_path def plugins_path
if site.config['plugins_dir'] == Jekyll::Configuration::DEFAULTS['plugins_dir'] if site.config['plugins_dir'].eql? Jekyll::Configuration::DEFAULTS['plugins_dir']
[site.in_source_dir(site.config['plugins_dir'])] [site.in_source_dir(site.config['plugins_dir'])]
else else
Array(site.config['plugins_dir']).map { |d| File.expand_path(d) } Array(site.config['plugins_dir']).map { |d| File.expand_path(d) }

View File

@ -54,6 +54,10 @@ module Jekyll
target.default_proc = overwrite.default_proc target.default_proc = overwrite.default_proc
end end
target.each do |key, val|
target[key] = val.dup if val.frozen? && duplicable?(val)
end
target target
end end
@ -61,6 +65,15 @@ module Jekyll
value.is_a?(Hash) || value.is_a?(Drops::Drop) value.is_a?(Hash) || value.is_a?(Drops::Drop)
end end
def duplicable?(obj)
case obj
when nil, false, true, Symbol, Numeric
false
else
true
end
end
# Read array from the supplied hash favouring the singular key # Read array from the supplied hash favouring the singular key
# and then the plural key, and handling any nil entries. # and then the plural key, and handling any nil entries.
# #

View File

@ -61,8 +61,30 @@ module Minitest::Assertions
end end
end end
module DirectoryHelpers
def dest_dir(*subdirs)
test_dir("dest", *subdirs)
end
def source_dir(*subdirs)
test_dir("source", *subdirs)
end
def test_dir(*subdirs)
File.join(File.dirname(__FILE__), *subdirs)
end
end
class JekyllUnitTest < Minitest::Test class JekyllUnitTest < Minitest::Test
include ::RSpec::Mocks::ExampleMethods include ::RSpec::Mocks::ExampleMethods
include DirectoryHelpers
extend DirectoryHelpers
def mu_pp(obj)
s = obj.is_a?(Hash) ? JSON.pretty_generate(obj) : obj.inspect
s = s.encode Encoding.default_external if defined? Encoding
s
end
def mocks_expect(*args) def mocks_expect(*args)
RSpec::Mocks::ExampleMethods::ExpectHost.instance_method(:expect)\ RSpec::Mocks::ExampleMethods::ExpectHost.instance_method(:expect)\
@ -85,9 +107,12 @@ class JekyllUnitTest < Minitest::Test
Jekyll::Site.new(site_configuration(overrides)) Jekyll::Site.new(site_configuration(overrides))
end end
def build_configs(overrides, base_hash = Jekyll::Configuration::DEFAULTS) def default_configuration
Marshal.load(Marshal.dump(Jekyll::Configuration::DEFAULTS))
end
def build_configs(overrides, base_hash = default_configuration)
Utils.deep_merge_hashes(base_hash, overrides) Utils.deep_merge_hashes(base_hash, overrides)
.fix_common_issues.backwards_compatibilize.add_default_collections
end end
def site_configuration(overrides = {}) def site_configuration(overrides = {})
@ -98,14 +123,9 @@ class JekyllUnitTest < Minitest::Test
build_configs({ build_configs({
"source" => source_dir "source" => source_dir
}, full_overrides) }, full_overrides)
end .fix_common_issues
.backwards_compatibilize
def dest_dir(*subdirs) .add_default_collections
test_dir("dest", *subdirs)
end
def source_dir(*subdirs)
test_dir("source", *subdirs)
end end
def clear_dest def clear_dest
@ -113,10 +133,6 @@ class JekyllUnitTest < Minitest::Test
FileUtils.rm_rf(source_dir(".jekyll-metadata")) FileUtils.rm_rf(source_dir(".jekyll-metadata"))
end end
def test_dir(*subdirs)
File.join(File.dirname(__FILE__), *subdirs)
end
def directory_with_contents(path) def directory_with_contents(path)
FileUtils.rm_rf(path) FileUtils.rm_rf(path)
FileUtils.mkdir(path) FileUtils.mkdir(path)

View File

@ -1,7 +1,62 @@
require 'helper' require 'helper'
class TestConfiguration < JekyllUnitTest class TestConfiguration < JekyllUnitTest
@@defaults = Jekyll::Configuration::DEFAULTS.add_default_collections.freeze @@test_config = {
"source" => new(nil).source_dir,
"destination" => dest_dir
}
context ".from" do
should "create a Configuration object" do
assert_instance_of Configuration, Configuration.from({})
end
should "merge input over defaults" do
result = Configuration.from({"source" => "blah"})
refute_equal result["source"], Configuration::DEFAULTS["source"]
assert_equal result["source"], "blah"
end
should "fix common mistakes" do
result = Configuration.from({"paginate" => 0})
assert_nil result["paginate"], "Expected 'paginate' to be corrected to 'nil', but was #{result["paginate"].inspect}"
end
should "add default collections" do
result = Configuration.from({})
assert_equal result["collections"], {"posts" => {"output" => true, "permalink" => "/:categories/:year/:month/:day/:title:output_ext"}}
end
should "NOT backwards-compatibilize" do
assert Configuration.from("watch" => true)["watch"], "Expected the 'watch' key to not be removed."
end
end
context "#add_default_collections" do
should "no-op if collections is nil" do
result = Configuration[{"collections" => nil}].add_default_collections
assert_nil result["collections"]
end
should "turn an array into a hash" do
result = Configuration[{"collections" => %w{methods}}].add_default_collections
assert_instance_of Hash, result["collections"]
assert_equal result["collections"], {"posts" => {"output" => true}, "methods" => {}}
end
should "only assign collections.posts.permalink if a permalink is specified" do
result = Configuration[{"permalink" => "pretty", "collections" => {}}].add_default_collections
assert_equal result["collections"], {"posts" => {"output" => true, "permalink" => "/:categories/:year/:month/:day/:title/"}}
result = Configuration[{"permalink" => nil, "collections" => {}}].add_default_collections
assert_equal result["collections"], {"posts" => {"output" => true}}
end
should "forces posts to output" do
result = Configuration[{"collections" => {"posts" => {"output" => false}}}].add_default_collections
assert_equal result["collections"]["posts"]["output"], true
end
end
context "#stringify_keys" do context "#stringify_keys" do
setup do setup do
@ -154,27 +209,27 @@ class TestConfiguration < JekyllUnitTest
end end
context "loading configuration" do context "loading configuration" do
setup do setup do
@path = File.join(Dir.pwd, '_config.yml') @path = source_dir('_config.yml')
@user_config = File.join(Dir.pwd, "my_config_file.yml") @user_config = File.join(Dir.pwd, "my_config_file.yml")
end end
should "fire warning with no _config.yml" do should "fire warning with no _config.yml" do
allow(SafeYAML).to receive(:load_file).with(@path) { raise SystemCallError, "No such file or directory - #{@path}" } allow(SafeYAML).to receive(:load_file).with(@path) { raise SystemCallError, "No such file or directory - #{@path}" }
allow($stderr).to receive(:puts).with("Configuration file: none".yellow) allow($stderr).to receive(:puts).with("Configuration file: none".yellow)
assert_equal @@defaults, Jekyll.configuration({}) assert_equal site_configuration, Jekyll.configuration(@@test_config)
end end
should "load configuration as hash" do should "load configuration as hash" do
allow(SafeYAML).to receive(:load_file).with(@path).and_return(Hash.new) allow(SafeYAML).to receive(:load_file).with(@path).and_return(Hash.new)
allow($stdout).to receive(:puts).with("Configuration file: #{@path}") allow($stdout).to receive(:puts).with("Configuration file: #{@path}")
assert_equal @@defaults, Jekyll.configuration({}) assert_equal site_configuration, Jekyll.configuration(@@test_config)
end end
should "fire warning with bad config" do should "fire warning with bad config" do
allow(SafeYAML).to receive(:load_file).with(@path).and_return(Array.new) allow(SafeYAML).to receive(:load_file).with(@path).and_return(Array.new)
allow($stderr).to receive(:puts).and_return(("WARNING: ".rjust(20) + "Error reading configuration. Using defaults (and options).").yellow) allow($stderr).to receive(:puts).and_return(("WARNING: ".rjust(20) + "Error reading configuration. Using defaults (and options).").yellow)
allow($stderr).to receive(:puts).and_return("Configuration file: (INVALID) #{@path}".yellow) allow($stderr).to receive(:puts).and_return("Configuration file: (INVALID) #{@path}".yellow)
assert_equal @@defaults, Jekyll.configuration({}) assert_equal site_configuration, Jekyll.configuration(@@test_config)
end end
should "fire warning when user-specified config file isn't there" do should "fire warning when user-specified config file isn't there" do
@ -193,8 +248,8 @@ class TestConfiguration < JekyllUnitTest
context "loading config from external file" do context "loading config from external file" do
setup do setup do
@paths = { @paths = {
:default => File.join(Dir.pwd, '_config.yml'), :default => source_dir('_config.yml'),
:other => File.join(Dir.pwd, '_config.live.yml'), :other => source_dir('_config.live.yml'),
:toml => source_dir('_config.dev.toml'), :toml => source_dir('_config.dev.toml'),
:empty => "" :empty => ""
} }
@ -203,24 +258,31 @@ class TestConfiguration < JekyllUnitTest
should "load default plus posts config if no config_file is set" do should "load default plus posts config if no config_file is set" do
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({}) allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
assert_equal @@defaults, Jekyll.configuration({}) assert_equal site_configuration, Jekyll.configuration(@@test_config)
end end
should "load different config if specified" do should "load different config if specified" do
allow(SafeYAML).to receive(:load_file).with(@paths[:other]).and_return({"baseurl" => "http://wahoo.dev"}) allow(SafeYAML).to receive(:load_file).with(@paths[:other]).and_return({"baseurl" => "http://wahoo.dev"})
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
assert_equal Utils.deep_merge_hashes(@@defaults, { "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => @paths[:other] }) Jekyll.configuration({ "config" => @paths[:other] })
assert_equal \
site_configuration({ "baseurl" => "http://wahoo.dev" }),
Jekyll.configuration(@@test_config.merge({ "config" => @paths[:other] }))
end end
should "load default config if path passed is empty" do should "load default config if path passed is empty" do
allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({}) allow(SafeYAML).to receive(:load_file).with(@paths[:default]).and_return({})
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
assert_equal @@defaults, Jekyll.configuration({ "config" => @paths[:empty] }) assert_equal \
site_configuration,
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:empty]] }))
end end
should "successfully load a TOML file" do should "successfully load a TOML file" do
Jekyll.logger.log_level = :warn Jekyll.logger.log_level = :warn
assert_equal @@defaults.clone.merge({ "baseurl" => "/you-beautiful-blog-you", "title" => "My magnificent site, wut" }), Jekyll.configuration({ "config" => [@paths[:toml]] }) assert_equal \
site_configuration({ "baseurl" => "/you-beautiful-blog-you", "title" => "My magnificent site, wut" }),
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:toml]] }))
Jekyll.logger.log_level = :info Jekyll.logger.log_level = :info
end end
@ -233,7 +295,9 @@ class TestConfiguration < JekyllUnitTest
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:toml]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:toml]}")
assert_equal @@defaults, Jekyll.configuration({ "config" => [@paths[:default], @paths[:other], @paths[:toml]] }) assert_equal \
site_configuration,
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:default], @paths[:other], @paths[:toml]] }))
end end
should "load multiple config files and last config should win" do should "load multiple config files and last config should win" do
@ -241,7 +305,63 @@ class TestConfiguration < JekyllUnitTest
allow(SafeYAML).to receive(:load_file).with(@paths[:other]).and_return({"baseurl" => "http://wahoo.dev"}) allow(SafeYAML).to receive(:load_file).with(@paths[:other]).and_return({"baseurl" => "http://wahoo.dev"})
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:default]}")
allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}") allow($stdout).to receive(:puts).with("Configuration file: #{@paths[:other]}")
assert_equal Utils.deep_merge_hashes(@@defaults, { "baseurl" => "http://wahoo.dev" }), Jekyll.configuration({ "config" => [@paths[:default], @paths[:other]] }) assert_equal \
site_configuration({ "baseurl" => "http://wahoo.dev" }),
Jekyll.configuration(@@test_config.merge({ "config" => [@paths[:default], @paths[:other]] }))
end
end
context "#add_default_collections" do
should "not do anything if collections is nil" do
conf = Configuration[default_configuration].tap {|c| c['collections'] = nil }
assert_equal conf.add_default_collections, conf
assert_nil conf.add_default_collections['collections']
end
should "converts collections to a hash if an array" do
conf = Configuration[default_configuration].tap {|c| c['collections'] = ['docs'] }
assert_equal conf.add_default_collections, conf.merge({
"collections" => {
"docs" => {},
"posts" => {
"output" => true,
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
}}})
end
should "force collections.posts.output = true" do
conf = Configuration[default_configuration].tap {|c| c['collections'] = {'posts' => {'output' => false}} }
assert_equal conf.add_default_collections, conf.merge({
"collections" => {
"posts" => {
"output" => true,
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
}}})
end
should "set collections.posts.permalink if it's not set" do
conf = Configuration[default_configuration]
assert_equal conf.add_default_collections, conf.merge({
"collections" => {
"posts" => {
"output" => true,
"permalink" => "/:categories/:year/:month/:day/:title:output_ext"
}}})
end
should "leave collections.posts.permalink alone if it is set" do
posts_permalink = "/:year/:title/"
conf = Configuration[default_configuration].tap do |c|
c['collections'] = {
"posts" => { "permalink" => posts_permalink }
}
end
assert_equal conf.add_default_collections, conf.merge({
"collections" => {
"posts" => {
"output" => true,
"permalink" => posts_permalink
}}})
end end
end end
end end

View File

@ -3,10 +3,8 @@ require "helper"
class TestFrontMatterDefaults < JekyllUnitTest class TestFrontMatterDefaults < JekyllUnitTest
context "A site with full front matter defaults" do context "A site with full front matter defaults" do
setup do setup do
@site = Site.new(Jekyll.configuration({ @site = fixture_site({
"source" => source_dir, "defaults" => [{
"destination" => dest_dir,
"defaults" => [{
"scope" => { "scope" => {
"path" => "contacts", "path" => "contacts",
"type" => "page" "type" => "page"
@ -15,7 +13,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val" "key" => "val"
} }
}] }]
})) })
@site.process @site.process
@affected = @site.pages.find { |page| page.relative_path == "/contacts/bar.html" } @affected = @site.pages.find { |page| page.relative_path == "/contacts/bar.html" }
@not_affected = @site.pages.find { |page| page.relative_path == "about.html" } @not_affected = @site.pages.find { |page| page.relative_path == "about.html" }
@ -29,10 +27,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter type pages and an extension" do context "A site with front matter type pages and an extension" do
setup do setup do
@site = Site.new(Jekyll.configuration({ @site = fixture_site({
"source" => source_dir, "defaults" => [{
"destination" => dest_dir,
"defaults" => [{
"scope" => { "scope" => {
"path" => "index.html" "path" => "index.html"
}, },
@ -40,7 +36,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val" "key" => "val"
} }
}] }]
})) })
@site.process @site.process
@affected = @site.pages.find { |page| page.relative_path == "index.html" } @affected = @site.pages.find { |page| page.relative_path == "index.html" }
@ -55,10 +51,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no type" do context "A site with front matter defaults with no type" do
setup do setup do
@site = Site.new(Jekyll.configuration({ @site = fixture_site({
"source" => source_dir, "defaults" => [{
"destination" => dest_dir,
"defaults" => [{
"scope" => { "scope" => {
"path" => "win" "path" => "win"
}, },
@ -66,7 +60,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val" "key" => "val"
} }
}] }]
})) })
@site.process @site.process
@affected = @site.posts.docs.find { |page| page.relative_path =~ %r!win\/! } @affected = @site.posts.docs.find { |page| page.relative_path =~ %r!win\/! }
@not_affected = @site.pages.find { |page| page.relative_path == "about.html" } @not_affected = @site.pages.find { |page| page.relative_path == "about.html" }
@ -80,10 +75,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no path and a deprecated type" do context "A site with front matter defaults with no path and a deprecated type" do
setup do setup do
@site = Site.new(Jekyll.configuration({ @site = fixture_site({
"source" => source_dir, "defaults" => [{
"destination" => dest_dir,
"defaults" => [{
"scope" => { "scope" => {
"type" => "page" "type" => "page"
}, },
@ -91,7 +84,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val" "key" => "val"
} }
}] }]
})) })
@site.process @site.process
@affected = @site.pages @affected = @site.pages
@not_affected = @site.posts.docs @not_affected = @site.posts.docs
@ -106,10 +100,8 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no path" do context "A site with front matter defaults with no path" do
setup do setup do
@site = Site.new(Jekyll.configuration({ @site = fixture_site({
"source" => source_dir, "defaults" => [{
"destination" => dest_dir,
"defaults" => [{
"scope" => { "scope" => {
"type" => "pages" "type" => "pages"
}, },
@ -117,7 +109,7 @@ class TestFrontMatterDefaults < JekyllUnitTest
"key" => "val" "key" => "val"
} }
}] }]
})) })
@site.process @site.process
@affected = @site.pages @affected = @site.pages
@not_affected = @site.posts.docs @not_affected = @site.posts.docs
@ -132,17 +124,15 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no path or type" do context "A site with front matter defaults with no path or type" do
setup do setup do
@site = Site.new(Jekyll.configuration({ @site = fixture_site({
"source" => source_dir, "defaults" => [{
"destination" => dest_dir,
"defaults" => [{
"scope" => { "scope" => {
}, },
"values" => { "values" => {
"key" => "val" "key" => "val"
} }
}] }]
})) })
@site.process @site.process
@affected = @site.pages @affected = @site.pages
@not_affected = @site.posts @not_affected = @site.posts
@ -156,15 +146,13 @@ class TestFrontMatterDefaults < JekyllUnitTest
context "A site with front matter defaults with no scope" do context "A site with front matter defaults with no scope" do
setup do setup do
@site = Site.new(Jekyll.configuration({ @site = fixture_site({
"source" => source_dir, "defaults" => [{
"destination" => dest_dir,
"defaults" => [{
"values" => { "values" => {
"key" => "val" "key" => "val"
} }
}] }]
})) })
@site.process @site.process
@affected = @site.pages @affected = @site.pages
@not_affected = @site.posts @not_affected = @site.posts

View File

@ -4,10 +4,8 @@ class TestGeneratedSite < JekyllUnitTest
context "generated sites" do context "generated sites" do
setup do setup do
clear_dest clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({ "source" => source_dir,
"destination" => dest_dir })
@site = fixture_site(config) @site = fixture_site
@site.process @site.process
@index = File.read(dest_dir("index.html")) @index = File.read(dest_dir("index.html"))
end end
@ -65,10 +63,7 @@ OUTPUT
context "generating limited posts" do context "generating limited posts" do
setup do setup do
clear_dest clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({ "source" => source_dir, @site = fixture_site("limit_posts" => 5)
"destination" => dest_dir,
"limit_posts" => 5 })
@site = fixture_site(config)
@site.process @site.process
@index = File.read(dest_dir("index.html")) @index = File.read(dest_dir("index.html"))
end end
@ -80,24 +75,16 @@ OUTPUT
should "ensure limit posts is 0 or more" do should "ensure limit posts is 0 or more" do
assert_raises ArgumentError do assert_raises ArgumentError do
clear_dest clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({ @site = fixture_site("limit_posts" => -1)
"source" => source_dir,
"destination" => dest_dir,
"limit_posts" => -1
})
@site = fixture_site(config)
end end
end end
should "acceptable limit post is 0" do should "acceptable limit post is 0" do
clear_dest clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({ assert(
"source" => source_dir, fixture_site("limit_posts" => 0),
"destination" => dest_dir, "Couldn't create a site with limit_posts=0."
"limit_posts" => 0 )
})
assert Site.new(config), "Couldn't create a site with the given limit_posts."
end end
end end
end end

View File

@ -3,42 +3,42 @@ require 'helper'
class TestSite < JekyllUnitTest class TestSite < JekyllUnitTest
context "configuring sites" do context "configuring sites" do
should "have an array for plugins by default" do should "have an array for plugins by default" do
site = Site.new(Jekyll::Configuration::DEFAULTS) site = Site.new default_configuration
assert_equal [File.join(Dir.pwd, '_plugins')], site.plugins assert_equal [File.join(Dir.pwd, '_plugins')], site.plugins
end end
should "look for plugins under the site directory by default" do should "look for plugins under the site directory by default" do
site = Site.new(site_configuration) site = Site.new(site_configuration)
assert_equal [File.join(source_dir, '_plugins')], site.plugins assert_equal [source_dir('_plugins')], site.plugins
end end
should "have an array for plugins if passed as a string" do should "have an array for plugins if passed as a string" do
site = Site.new(Jekyll::Configuration::DEFAULTS.merge({'plugins_dir' => '/tmp/plugins'})) site = Site.new(site_configuration({ 'plugins_dir' => '/tmp/plugins' }))
assert_equal ['/tmp/plugins'], site.plugins assert_equal ['/tmp/plugins'], site.plugins
end end
should "have an array for plugins if passed as an array" do should "have an array for plugins if passed as an array" do
site = Site.new(Jekyll::Configuration::DEFAULTS.merge({'plugins_dir' => ['/tmp/plugins', '/tmp/otherplugins']})) site = Site.new(site_configuration({ 'plugins_dir' => ['/tmp/plugins', '/tmp/otherplugins'] }))
assert_equal ['/tmp/plugins', '/tmp/otherplugins'], site.plugins assert_equal ['/tmp/plugins', '/tmp/otherplugins'], site.plugins
end end
should "have an empty array for plugins if nothing is passed" do should "have an empty array for plugins if nothing is passed" do
site = Site.new(Jekyll::Configuration::DEFAULTS.merge({'plugins_dir' => []})) site = Site.new(site_configuration({ 'plugins_dir' => [] }))
assert_equal [], site.plugins assert_equal [], site.plugins
end end
should "have an empty array for plugins if nil is passed" do should "have the default for plugins if nil is passed" do
site = Site.new(Jekyll::Configuration::DEFAULTS.merge({'plugins_dir' => nil})) site = Site.new(site_configuration({ 'plugins_dir' => nil }))
assert_equal [], site.plugins assert_equal [source_dir('_plugins')], site.plugins
end end
should "expose default baseurl" do should "expose default baseurl" do
site = Site.new(Jekyll::Configuration::DEFAULTS) site = Site.new(default_configuration)
assert_equal Jekyll::Configuration::DEFAULTS['baseurl'], site.baseurl assert_equal Jekyll::Configuration::DEFAULTS['baseurl'], site.baseurl
end end
should "expose baseurl passed in from config" do should "expose baseurl passed in from config" do
site = Site.new(Jekyll::Configuration::DEFAULTS.merge({'baseurl' => '/blog'})) site = Site.new(site_configuration({ 'baseurl' => '/blog' }))
assert_equal '/blog', site.baseurl assert_equal '/blog', site.baseurl
end end
end end