Rubocop: test/test_page.rb

This commit is contained in:
Pat Hawks 2016-05-25 22:00:15 -05:00
parent 7537b01e74
commit 474fc0a9a8
1 changed files with 75 additions and 73 deletions

View File

@ -1,15 +1,18 @@
require 'helper' require "helper"
class TestPage < JekyllUnitTest class TestPage < JekyllUnitTest
def setup_page(*args) def setup_page(*args)
dir, file = args dir, file = args
dir, file = ['', dir] if file.nil? if file.nil?
file = dir
dir = ""
end
@page = Page.new(@site, source_dir, dir, file) @page = Page.new(@site, source_dir, dir, file)
end end
def do_render(page) def do_render(page)
layouts = { layouts = {
"default" => Layout.new(@site, source_dir('_layouts'), "simple.html") "default" => Layout.new(@site, source_dir("_layouts"), "simple.html")
} }
page.render(layouts, @site.site_payload) page.render(layouts, @site.site_payload)
end end
@ -26,7 +29,7 @@ class TestPage < JekyllUnitTest
context "processing pages" do context "processing pages" do
should "create url based on filename" do should "create url based on filename" do
@page = setup_page('contacts.html') @page = setup_page("contacts.html")
assert_equal "/contacts.html", @page.url assert_equal "/contacts.html", @page.url
end end
@ -36,29 +39,29 @@ class TestPage < JekyllUnitTest
end end
should "create url with non-alphabetic characters" do should "create url with non-alphabetic characters" do
@page = setup_page('+', '%# +.md') @page = setup_page("+", '%# +.md')
assert_equal "/+/%25%23%20+.html", @page.url assert_equal "/+/%25%23%20+.html", @page.url
end end
context "in a directory hierarchy" do context "in a directory hierarchy" do
should "create url based on filename" do should "create url based on filename" do
@page = setup_page('/contacts', 'bar.html') @page = setup_page("/contacts", "bar.html")
assert_equal "/contacts/bar.html", @page.url assert_equal "/contacts/bar.html", @page.url
end end
should "create index url based on filename" do should "create index url based on filename" do
@page = setup_page('/contacts', 'index.html') @page = setup_page("/contacts", "index.html")
assert_equal "/contacts/", @page.url assert_equal "/contacts/", @page.url
end end
end end
should "deal properly with extensions" do should "deal properly with extensions" do
@page = setup_page('deal.with.dots.html') @page = setup_page("deal.with.dots.html")
assert_equal ".html", @page.ext assert_equal ".html", @page.ext
end end
should "deal properly with non-html extensions" do should "deal properly with non-html extensions" do
@page = setup_page('dynamic_page.php') @page = setup_page("dynamic_page.php")
@dest_file = dest_dir("dynamic_page.php") @dest_file = dest_dir("dynamic_page.php")
assert_equal ".php", @page.ext assert_equal ".php", @page.ext
assert_equal "dynamic_page", @page.basename assert_equal "dynamic_page", @page.basename
@ -67,7 +70,7 @@ class TestPage < JekyllUnitTest
end end
should "deal properly with dots" do should "deal properly with dots" do
@page = setup_page('deal.with.dots.html') @page = setup_page("deal.with.dots.html")
@dest_file = dest_dir("deal.with.dots.html") @dest_file = dest_dir("deal.with.dots.html")
assert_equal "deal.with.dots", @page.basename assert_equal "deal.with.dots", @page.basename
@ -75,19 +78,19 @@ class TestPage < JekyllUnitTest
end end
should "make properties accessible through #[]" do should "make properties accessible through #[]" do
page = setup_page('properties.html') page = setup_page("properties.html")
attrs = { attrs = {
content: "All the properties.\n", :content => "All the properties.\n",
dir: "/properties/", :dir => "/properties/",
excerpt: nil, :excerpt => nil,
foo: 'bar', :foo => "bar",
layout: 'default', :layout => "default",
name: "properties.html", :name => "properties.html",
path: "properties.html", :path => "properties.html",
permalink: '/properties/', :permalink => "/properties/",
published: nil, :published => nil,
title: 'Properties Page', :title => "Properties Page",
url: "/properties/" :url => "/properties/"
} }
attrs.each do |attr, val| attrs.each do |attr, val|
@ -103,38 +106,38 @@ class TestPage < JekyllUnitTest
end end
should "return dir, url, and destination correctly" do should "return dir, url, and destination correctly" do
@page = setup_page('contacts.html') @page = setup_page("contacts.html")
@dest_file = dest_dir("contacts/index.html") @dest_file = dest_dir("contacts/index.html")
assert_equal '/contacts/', @page.dir assert_equal "/contacts/", @page.dir
assert_equal '/contacts/', @page.url assert_equal "/contacts/", @page.url
assert_equal @dest_file, @page.destination(dest_dir) assert_equal @dest_file, @page.destination(dest_dir)
end end
should "return dir correctly for index page" do should "return dir correctly for index page" do
@page = setup_page('index.html') @page = setup_page("index.html")
assert_equal '/', @page.dir assert_equal "/", @page.dir
end end
context "in a directory hierarchy" do context "in a directory hierarchy" do
should "create url based on filename" do should "create url based on filename" do
@page = setup_page('/contacts', 'bar.html') @page = setup_page("/contacts", "bar.html")
assert_equal "/contacts/bar/", @page.url assert_equal "/contacts/bar/", @page.url
end end
should "create index url based on filename" do should "create index url based on filename" do
@page = setup_page('/contacts', 'index.html') @page = setup_page("/contacts", "index.html")
assert_equal "/contacts/", @page.url assert_equal "/contacts/", @page.url
end end
should "return dir correctly" do should "return dir correctly" do
@page = setup_page('/contacts', 'bar.html') @page = setup_page("/contacts", "bar.html")
assert_equal '/contacts/bar/', @page.dir assert_equal "/contacts/bar/", @page.dir
end end
should "return dir correctly for index page" do should "return dir correctly for index page" do
@page = setup_page('/contacts', 'index.html') @page = setup_page("/contacts", "index.html")
assert_equal '/contacts/', @page.dir assert_equal "/contacts/", @page.dir
end end
end end
end end
@ -145,16 +148,16 @@ class TestPage < JekyllUnitTest
end end
should "return url and destination correctly" do should "return url and destination correctly" do
@page = setup_page('contacts.html') @page = setup_page("contacts.html")
@dest_file = dest_dir("contacts.html") @dest_file = dest_dir("contacts.html")
assert_equal '/contacts.html', @page.url assert_equal "/contacts.html", @page.url
assert_equal @dest_file, @page.destination(dest_dir) assert_equal @dest_file, @page.destination(dest_dir)
end end
should "return dir correctly" do should "return dir correctly" do
assert_equal '/', setup_page('contacts.html').dir assert_equal "/", setup_page("contacts.html").dir
assert_equal '/contacts/', setup_page('contacts/bar.html').dir assert_equal "/contacts/", setup_page("contacts/bar.html").dir
assert_equal '/contacts/', setup_page('contacts/index.html').dir assert_equal "/contacts/", setup_page("contacts/index.html").dir
end end
end end
@ -164,9 +167,9 @@ class TestPage < JekyllUnitTest
end end
should "return url and destination correctly" do should "return url and destination correctly" do
@page = setup_page('contacts.html') @page = setup_page("contacts.html")
@dest_file = dest_dir("contacts/index.html") @dest_file = dest_dir("contacts/index.html")
assert_equal '/contacts/', @page.url assert_equal "/contacts/", @page.url
assert_equal @dest_file, @page.destination(dest_dir) assert_equal @dest_file, @page.destination(dest_dir)
end end
end end
@ -177,9 +180,9 @@ class TestPage < JekyllUnitTest
end end
should "return url and destination correctly" do should "return url and destination correctly" do
@page = setup_page('contacts.html') @page = setup_page("contacts.html")
@dest_file = dest_dir("contacts.html") @dest_file = dest_dir("contacts.html")
assert_equal '/contacts.html', @page.url assert_equal "/contacts.html", @page.url
assert_equal @dest_file, @page.destination(dest_dir) assert_equal @dest_file, @page.destination(dest_dir)
end end
end end
@ -190,9 +193,9 @@ class TestPage < JekyllUnitTest
end end
should "return url and destination correctly" do should "return url and destination correctly" do
@page = setup_page('contacts.html') @page = setup_page("contacts.html")
@dest_file = dest_dir("contacts.html") @dest_file = dest_dir("contacts.html")
assert_equal '/contacts', @page.url assert_equal "/contacts", @page.url
assert_equal @dest_file, @page.destination(dest_dir) assert_equal @dest_file, @page.destination(dest_dir)
end end
end end
@ -200,9 +203,9 @@ class TestPage < JekyllUnitTest
context "with any other permalink style" do context "with any other permalink style" do
should "return dir correctly" do should "return dir correctly" do
@site.permalink_style = nil @site.permalink_style = nil
assert_equal '/', setup_page('contacts.html').dir assert_equal "/", setup_page("contacts.html").dir
assert_equal '/contacts/', setup_page('contacts/index.html').dir assert_equal "/contacts/", setup_page("contacts/index.html").dir
assert_equal '/contacts/', setup_page('contacts/bar.html').dir assert_equal "/contacts/", setup_page("contacts/bar.html").dir
end end
end end
@ -216,7 +219,7 @@ class TestPage < JekyllUnitTest
end end
should "return nil permalink if no permalink exists" do should "return nil permalink if no permalink exists" do
@page = setup_page('') @page = setup_page("")
assert_equal nil, @page.permalink assert_equal nil, @page.permalink
end end
@ -233,7 +236,7 @@ class TestPage < JekyllUnitTest
context "with specified layout of nil" do context "with specified layout of nil" do
setup do setup do
@page = setup_page('sitemap.xml') @page = setup_page("sitemap.xml")
end end
should "layout of nil is respected" do should "layout of nil is respected" do
@ -247,60 +250,60 @@ class TestPage < JekyllUnitTest
end end
should "write properly" do should "write properly" do
page = setup_page('contacts.html') page = setup_page("contacts.html")
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert_exist dest_dir('contacts.html') assert_exist dest_dir("contacts.html")
end end
should "write even when the folder name is plus and permalink has +" do should "write even when the folder name is plus and permalink has +" do
page = setup_page('+', 'foo.md') page = setup_page("+", "foo.md")
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir), "#{dest_dir} should be a directory" assert File.directory?(dest_dir), "#{dest_dir} should be a directory"
assert_exist dest_dir('+', 'plus+in+url.html') assert_exist dest_dir("+", "plus+in+url.html")
end end
should "write even when permalink has '%# +'" do should "write even when permalink has '%# +'" do
page = setup_page('+', '%# +.md') page = setup_page("+", '%# +.md')
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert_exist dest_dir('+', '%# +.html') assert_exist dest_dir("+", '%# +.html')
end end
should "write properly without html extension" do should "write properly without html extension" do
page = setup_page('contacts.html') page = setup_page("contacts.html")
page.site.permalink_style = :pretty page.site.permalink_style = :pretty
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert_exist dest_dir('contacts', 'index.html') assert_exist dest_dir("contacts", "index.html")
end end
should "support .htm extension and respects that" do should "support .htm extension and respects that" do
page = setup_page('contacts.htm') page = setup_page("contacts.htm")
page.site.permalink_style = :pretty page.site.permalink_style = :pretty
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert_exist dest_dir('contacts', 'index.htm') assert_exist dest_dir("contacts", "index.htm")
end end
should "support .xhtml extension and respects that" do should "support .xhtml extension and respects that" do
page = setup_page('contacts.xhtml') page = setup_page("contacts.xhtml")
page.site.permalink_style = :pretty page.site.permalink_style = :pretty
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert_exist dest_dir('contacts', 'index.xhtml') assert_exist dest_dir("contacts", "index.xhtml")
end end
should "write properly with extension different from html" do should "write properly with extension different from html" do
@ -312,48 +315,47 @@ class TestPage < JekyllUnitTest
assert_equal "/sitemap.xml", page.url assert_equal "/sitemap.xml", page.url
assert_nil page.url[/\.html$/] assert_nil page.url[/\.html$/]
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert_exist dest_dir('sitemap.xml') assert_exist dest_dir("sitemap.xml")
end end
should "write dotfiles properly" do should "write dotfiles properly" do
page = setup_page('.htaccess') page = setup_page(".htaccess")
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert_exist dest_dir('.htaccess') assert_exist dest_dir(".htaccess")
end end
context "in a directory hierarchy" do context "in a directory hierarchy" do
should "write properly the index" do should "write properly the index" do
page = setup_page('/contacts', 'index.html') page = setup_page("/contacts", "index.html")
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert_exist dest_dir('contacts', 'index.html') assert_exist dest_dir("contacts", "index.html")
end end
should "write properly" do should "write properly" do
page = setup_page('/contacts', 'bar.html') page = setup_page("/contacts", "bar.html")
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert_exist dest_dir('contacts', 'bar.html') assert_exist dest_dir("contacts", "bar.html")
end end
should "write properly without html extension" do should "write properly without html extension" do
page = setup_page('/contacts', 'bar.html') page = setup_page("/contacts", "bar.html")
page.site.permalink_style = :pretty page.site.permalink_style = :pretty
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert_exist dest_dir('contacts', 'bar', 'index.html') assert_exist dest_dir("contacts", "bar", "index.html")
end end
end end
end end
end end
end end