From 89e45afcc11954ee61d70d2b7d0aea2016d63625 Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Fri, 1 Aug 2014 10:28:53 -0700 Subject: [PATCH] Add tests for front matter defaults --- test/test_front_matter_defaults.rb | 127 +++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 test/test_front_matter_defaults.rb diff --git a/test/test_front_matter_defaults.rb b/test/test_front_matter_defaults.rb new file mode 100644 index 00000000..fe0244c8 --- /dev/null +++ b/test/test_front_matter_defaults.rb @@ -0,0 +1,127 @@ +require 'helper' + +class TestFrontMatterDefaults < Test::Unit::TestCase + + context "A site with full front matter defaults" do + setup do + @site = Site.new(Jekyll.configuration({ + "source" => source_dir, + "destination" => dest_dir, + "defaults" => [{ + "scope" => { + "path" => "contacts", + "type" => "page" + }, + "values" => { + "key" => "val" + } + }] + })) + @site.process + @affected = @site.pages.find { |page| page.relative_path == "/contacts/bar.html" } + @not_affected = @site.pages.find { |page| page.relative_path == "about.html" } + end + + should "affect only the specified path and type" do + assert_equal @affected.data["key"], "val" + assert_equal @not_affected.data["key"], nil + end + end + + context "A site with front matter defaults with no type" do + setup do + @site = Site.new(Jekyll.configuration({ + "source" => source_dir, + "destination" => dest_dir, + "defaults" => [{ + "scope" => { + "path" => "win" + }, + "values" => { + "key" => "val" + } + }] + })) + @site.process + @affected = @site.posts.find { |page| page.relative_path =~ /^\/win/ } + @not_affected = @site.pages.find { |page| page.relative_path == "about.html" } + end + + should "affect only the specified path and all types" do + assert_equal @affected.data["key"], "val" + assert_equal @not_affected.data["key"], nil + end + end + + context "A site with front matter defaults with no path" do + setup do + @site = Site.new(Jekyll.configuration({ + "source" => source_dir, + "destination" => dest_dir, + "defaults" => [{ + "scope" => { + "type" => "page" + }, + "values" => { + "key" => "val" + } + }] + })) + @site.process + @affected = @site.pages + @not_affected = @site.posts + end + + should "affect only the specified type and all paths" do + assert_equal @affected.reject { |page| page.data["key"] == "val" }, [] + assert_equal @not_affected.reject { |page| page.data["key"] == "val" }, @not_affected + end + end + + context "A site with front matter defaults with no path or type" do + setup do + @site = Site.new(Jekyll.configuration({ + "source" => source_dir, + "destination" => dest_dir, + "defaults" => [{ + "scope" => { + }, + "values" => { + "key" => "val" + } + }] + })) + @site.process + @affected = @site.pages + @not_affected = @site.posts + end + + should "affect all types and paths" do + assert_equal @affected.reject { |page| page.data["key"] == "val" }, [] + assert_equal @not_affected.reject { |page| page.data["key"] == "val" }, [] + end + end + + context "A site with front matter defaults with no scope" do + setup do + @site = Site.new(Jekyll.configuration({ + "source" => source_dir, + "destination" => dest_dir, + "defaults" => [{ + "values" => { + "key" => "val" + } + }] + })) + @site.process + @affected = @site.pages + @not_affected = @site.posts + end + + should "affect all types and paths" do + assert_equal @affected.reject { |page| page.data["key"] == "val" }, [] + assert_equal @not_affected.reject { |page| page.data["key"] == "val" }, [] + end + end + +end