From 0565308ce67be10530227997cabb58a55fb4f730 Mon Sep 17 00:00:00 2001 From: Martin Jorn Rogalla Date: Sun, 1 Mar 2015 09:40:32 +0100 Subject: [PATCH] Added test to check on nil input for sort filter. - Added a test to check if the sort filter will raise the correct exception on given nil input. - Improved error message and used "nil" consistently. Signed-off-by: Martin Jorn Rogalla --- lib/jekyll/filters.rb | 2 +- test/test_filters.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index e71710c9..ffdc3b73 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -223,7 +223,7 @@ module Jekyll # Returns the filtered array of objects def sort(input, property = nil, nils = "first") if input.nil? - raise ArgumentError.new("Invalid object array given. Object array is null.") + raise ArgumentError.new("Nil object array given. Sort cannot process an empty object array.") end if property.nil? input.sort diff --git a/test/test_filters.rb b/test/test_filters.rb index eec08564..642a6114 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -280,6 +280,12 @@ class TestFilters < JekyllUnitTest end context "sort filter" do + should "raise Exception when input is nil" do + err = assert_raises ArgumentError do + @filter.sort(nil) + end + assert_equal "Nil object array given. Sort cannot process an empty object array.", err.message + end should "return sorted numbers" do assert_equal [1, 2, 2.2, 3], @filter.sort([3, 2.2, 2, 1]) end