Rubocop: test/test_document.rb
This commit is contained in:
parent
fd75f0f7b1
commit
5291bd0498
|
@ -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.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,13 +102,12 @@ 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
|
||||
|
@ -117,7 +118,7 @@ class TestDocument < JekyllUnitTest
|
|||
"scope" => { "path"=>"", "type"=>"slides" },
|
||||
"values" => {
|
||||
"nested" => {
|
||||
"key"=>"myval",
|
||||
"key" => "myval"
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
@ -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
|
||||
|
||||
|
@ -166,7 +170,7 @@ class TestDocument < JekyllUnitTest
|
|||
"scope" => { "path"=>"_slides", "type"=>"slides" },
|
||||
"values" => {
|
||||
"nested" => {
|
||||
"key"=>"value123",
|
||||
"key" => "value123"
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
@ -190,7 +194,7 @@ class TestDocument < JekyllUnitTest
|
|||
"scope" => { "path"=>"somepath", "type"=>"slides" },
|
||||
"values" => {
|
||||
"nested" => {
|
||||
"key"=>"myval",
|
||||
"key" => "myval"
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue