diff --git a/test/test_document.rb b/test/test_document.rb index fb503dcc..808ef2e7 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -1,7 +1,6 @@ -require 'helper' +require "helper" class TestDocument < JekyllUnitTest - def assert_equal_value(key, one, other) assert_equal(one[key], other[key]) end @@ -12,7 +11,9 @@ class TestDocument < JekyllUnitTest "collections" => ["methods"] }) @site.process - @document = @site.collections["methods"].docs.detect {|d| d.relative_path == "_methods/configuration.md" } + @document = @site.collections["methods"].docs.detect do |d| + d.relative_path == "_methods/configuration.md" + end end should "exist" do @@ -86,11 +87,12 @@ class TestDocument < JekyllUnitTest end context "with YAML ending in three dots" do - setup do - @site = fixture_site({"collections" => ["methods"]}) + @site = fixture_site({ "collections" => ["methods"] }) @site.process - @document = @site.collections["methods"].docs.detect {|d| d.relative_path == "_methods/yaml_with_dots.md" } + @document = @site.collections["methods"].docs.detect do |d| + d.relative_path == "_methods/yaml_with_dots.md" + end end should "know its data" do @@ -100,36 +102,35 @@ class TestDocument < JekyllUnitTest end should "output the collection name in the #to_liquid method" do - assert_equal @document.to_liquid['collection'], "methods" + assert_equal @document.to_liquid["collection"], "methods" end should "output its relative path as path in Liquid" do - assert_equal @document.to_liquid['path'], "_methods/configuration.md" + assert_equal @document.to_liquid["path"], "_methods/configuration.md" end - end context "a document as part of a collection with frontmatter defaults" do setup do @site = fixture_site({ "collections" => ["slides"], - "defaults" => [{ - "scope"=> {"path"=>"", "type"=>"slides"}, - "values"=> { - "nested"=> { - "key"=>"myval", + "defaults" => [{ + "scope" => { "path"=>"", "type"=>"slides" }, + "values" => { + "nested" => { + "key" => "myval" } } }] }) @site.process - @document = @site.collections["slides"].docs.select{|d| d.is_a?(Document) }.first + @document = @site.collections["slides"].docs.select { |d| d.is_a?(Document) }.first end should "know the frontmatter defaults" do assert_equal "Example slide", @document.data["title"] assert_equal "slide", @document.data["layout"] - assert_equal({"key"=>"myval"}, @document.data["nested"]) + assert_equal({ "key"=>"myval" }, @document.data["nested"]) end end @@ -137,12 +138,12 @@ class TestDocument < JekyllUnitTest setup do @site = fixture_site({ "collections" => ["slides"], - "defaults" => [{ - "scope"=> {"path"=>"", "type"=>"slides"}, - "values"=> { - "nested"=> { - "test1"=>"default1", - "test2"=>"default1" + "defaults" => [{ + "scope" => { "path"=>"", "type"=>"slides" }, + "values" => { + "nested" => { + "test1" => "default1", + "test2" => "default1" } } }] @@ -154,7 +155,10 @@ class TestDocument < JekyllUnitTest should "override default values in the document frontmatter" do assert_equal "Override title", @document.data["title"] assert_equal "slide", @document.data["layout"] - assert_equal({"test1"=>"override1","test2"=>"override2"}, @document.data["nested"]) + assert_equal( + { "test1"=>"override1", "test2"=>"override2" }, + @document.data["nested"] + ) end end @@ -162,11 +166,11 @@ class TestDocument < JekyllUnitTest setup do @site = fixture_site({ "collections" => ["slides"], - "defaults" => [{ - "scope"=> {"path"=>"_slides", "type"=>"slides"}, - "values"=> { - "nested"=> { - "key"=>"value123", + "defaults" => [{ + "scope" => { "path"=>"_slides", "type"=>"slides" }, + "values" => { + "nested" => { + "key" => "value123" } } }] @@ -178,7 +182,7 @@ class TestDocument < JekyllUnitTest should "know the frontmatter defaults" do assert_equal "Example slide", @document.data["title"] assert_equal "slide", @document.data["layout"] - assert_equal({"key"=>"value123"}, @document.data["nested"]) + assert_equal({ "key"=>"value123" }, @document.data["nested"]) end end @@ -186,11 +190,11 @@ class TestDocument < JekyllUnitTest setup do @site = fixture_site({ "collections" => ["slides"], - "defaults" => [{ - "scope"=> {"path"=>"somepath", "type"=>"slides"}, - "values"=> { - "nested"=> { - "key"=>"myval", + "defaults" => [{ + "scope" => { "path"=>"somepath", "type"=>"slides" }, + "values" => { + "nested" => { + "key" => "myval" } } }] @@ -234,7 +238,7 @@ class TestDocument < JekyllUnitTest "permalink" => "/slides/test/:name" } }, - "permalink" => "pretty" + "permalink" => "pretty" }) @site.process @document = @site.collections["slides"].docs[0] @@ -259,9 +263,9 @@ class TestDocument < JekyllUnitTest @site = fixture_site({ "collections" => { "slides" => { - "output" => true, + "output" => true } - }, + } }) @site.permalink_style = :pretty @site.process @@ -283,9 +287,9 @@ class TestDocument < JekyllUnitTest @site = fixture_site({ "collections" => { "slides" => { - "output" => true, + "output" => true } - }, + } }) @site.permalink_style = :pretty @site.process @@ -337,7 +341,7 @@ class TestDocument < JekyllUnitTest "output" => true, "permalink" => "/slides/:title" } - }, + } }) @site.process @document = @site.collections["slides"].docs[3] @@ -363,7 +367,10 @@ class TestDocument < JekyllUnitTest end should "produce the right URL if they have a wild slug" do - assert_equal "/slides/Well,-so-what-is-Jekyll,-then", @document_with_strange_slug.url + assert_equal( + "/slides/Well,-so-what-is-Jekyll,-then", + @document_with_strange_slug.url + ) end should "produce the right destination file if they have a wild slug" do dest_file = dest_dir("/slides/Well,-so-what-is-Jekyll,-then.html") @@ -373,9 +380,9 @@ class TestDocument < JekyllUnitTest context "document with a permalink with dots & a trailing slash" do setup do - @site = fixture_site({"collections" => { + @site = fixture_site({ "collections" => { "with.dots" => { "output" => true } - }}) + } }) @site.process @document = @site.collections["with.dots"].docs.last @dest_file = dest_dir("with.dots", "permalink.with.slash.tho", "index.html") @@ -401,7 +408,7 @@ class TestDocument < JekyllUnitTest "slides" => { "output" => true } - }, + } }) @site.process @files = @site.collections["slides"].docs @@ -409,13 +416,17 @@ class TestDocument < JekyllUnitTest context "without output overrides" do should "be output according to collection defaults" do - refute_nil @files.find { |doc| doc.relative_path == "_slides/example-slide-4.html" } + refute_nil @files.find do |doc| + doc.relative_path == "_slides/example-slide-4.html" + end end end context "with output overrides" do should "be output according its front matter" do - assert_nil @files.find { |doc| doc.relative_path == "_slides/non-outputted-slide.html" } + assert_nil @files.find { |doc| + doc.relative_path == "_slides/non-outputted-slide.html" + } end end end @@ -430,7 +441,9 @@ class TestDocument < JekyllUnitTest } }) @site.process - @document = @site.collections["slides"].files.find { |doc| doc.relative_path == "_slides/octojekyll.png" } + @document = @site.collections["slides"].files.find do |doc| + doc.relative_path == "_slides/octojekyll.png" + end @dest_file = dest_dir("slides/octojekyll.png") end @@ -458,10 +471,12 @@ class TestDocument < JekyllUnitTest "methods" => { "output" => true } - }, + } }) @site.process - @document = @site.collections["methods"].docs.find { |doc| doc.relative_path == "_methods/escape-+ #%20[].md" } + @document = @site.collections["methods"].docs.find do |doc| + doc.relative_path == "_methods/escape-+ #%20[].md" + end @dest_file = dest_dir("methods/escape-+ #%20[].html") end @@ -476,7 +491,5 @@ class TestDocument < JekyllUnitTest should "be output in the correct place" do assert_equal true, File.file?(@dest_file) end - end - end