Rubocop: test/test_document.rb

This commit is contained in:
Pat Hawks 2016-05-25 21:59:33 -05:00
parent fd75f0f7b1
commit 5291bd0498
1 changed files with 64 additions and 51 deletions

View File

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