From 62a396173938762047b35975ab71c70e4bb1a468 Mon Sep 17 00:00:00 2001 From: Chris Frederick Date: Tue, 2 Sep 2014 14:33:03 +0900 Subject: [PATCH] Add tests for Utils#slugify --- test/test_utils.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/test_utils.rb b/test/test_utils.rb index d4daa097..ddc8750e 100644 --- a/test/test_utils.rb +++ b/test/test_utils.rb @@ -97,4 +97,48 @@ class TestUtils < Test::Unit::TestCase end end + context "The \`Utils.slugify\` method" do + should "return nil if passed nil" do + begin + assert Utils.slugify(nil).nil? + rescue NoMethodError + assert false, "Threw NoMethodError" + end + end + + should "replace whitespace with hyphens" do + assert_equal "working-with-drafts", Utils.slugify("Working with drafts") + end + + should "replace consecutive whitespace with a single hyphen" do + assert_equal "basic-usage", Utils.slugify("Basic Usage") + end + + should "trim leading and trailing whitespace" do + assert_equal "working-with-drafts", Utils.slugify(" Working with drafts ") + end + + should "drop trailing punctuation" do + assert_equal "so-what-is-jekyll-exactly", Utils.slugify("So what is Jekyll, exactly?") + end + + should "ignore hyphens" do + assert_equal "pre-releases", Utils.slugify("Pre-releases") + end + + should "replace underscores with hyphens" do + assert_equal "the-config-yml-file", Utils.slugify("The _config.yml file") + end + + should "combine adjacent hyphens and spaces" do + assert_equal "customizing-git-git-hooks", Utils.slugify("Customizing Git - Git Hooks") + end + + should "not modify the original string" do + title = "Quick-start guide" + Utils.slugify(title) + assert_equal "Quick-start guide", title + end + end + end