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 <martin@martinrogalla.com>
This commit is contained in:
Martin Jorn Rogalla 2015-03-01 09:40:32 +01:00
parent 531d0fb261
commit 0565308ce6
2 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -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