From f27eb77d0bbbffaa2317f90b790be3b0491aa464 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Thu, 10 Nov 2016 15:20:11 -0800 Subject: [PATCH] Add failing test for permalink templates with trailing underscores --- test/helper.rb | 15 +++++++++++++++ test/test_url.rb | 34 +++++++++++----------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index ad88b5d0..0c6935a0 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -103,6 +103,21 @@ class JekyllUnitTest < Minitest::Test RSpec::Mocks.teardown end + def fixture_document(relative_path) + site = fixture_site({ + "collections" => { + "methods" => { + "output" => true + } + } + }) + site.read + matching_doc = site.collections["methods"].docs.find do |doc| + doc.relative_path == relative_path + end + [site, matching_doc] + end + def fixture_site(overrides = {}) Jekyll::Site.new(site_configuration(overrides)) end diff --git a/test/test_url.rb b/test/test_url.rb index 1a447116..c39e51f2 100644 --- a/test/test_url.rb +++ b/test/test_url.rb @@ -54,17 +54,7 @@ class TestURL < JekyllUnitTest end should "handle UrlDrop as a placeholder in addition to a hash" do - site = fixture_site({ - "collections" => { - "methods" => { - "output" => true - } - } - }) - site.read - matching_doc = site.collections["methods"].docs.find do |doc| - doc.relative_path == "_methods/escape-+ #%20[].md" - end + _, matching_doc = fixture_document("_methods/escape-+ #%20[].md") assert_equal "/methods/escape-+-20/escape-20.html", URL.new( :template => "/methods/:title/:name:output_ext", :placeholders => matching_doc.url_placeholders @@ -81,18 +71,16 @@ class TestURL < JekyllUnitTest end end - should "ignore NoMethodErrors when a placeholder is not found" do - site = fixture_site({ - "collections" => { - "methods" => { - "output" => true - } - } - }) - site.read - matching_doc = site.collections["methods"].docs.find do |doc| - doc.relative_path == "_methods/escape-+ #%20[].md" - end + should "check for key without trailing underscore" do + _, matching_doc = fixture_document("_methods/configuration.md") + assert_equal "/lol", URL.new( + :template => "/:year-:month-:day_:title", + :placeholders => matching_doc.url_placeholders + ).to_s + end + + should "raise custom error when URL placeholder doesn't have key" do + _, matching_doc = fixture_document("_methods/escape-+ #%20[].md") assert_raises NoMethodError do URL.new( :template => "/methods/:headline",