Exception handling for humans

Ability to pass exception_handler as a block to #render
and provide whatever behavior you want on handling exceptions

https://github.com/Shopify/liquid/pull/254
This commit is contained in:
Florian Weingarten
2014-07-24 14:44:02 +00:00
parent 034a47a6cf
commit 6c6350f18b
4 changed files with 30 additions and 6 deletions
+14
View File
@@ -153,4 +153,18 @@ class TemplateTest < Test::Unit::TestCase
end
assert_equal 'ruby error in drop', e.message
end
def test_exception_handler_doesnt_reraise_if_it_returns_false
exception = nil
Template.parse("{{ 1 | divided_by: 0 }}").render({}, exception_handler: ->(e) { exception = e; false })
assert exception.is_a?(ZeroDivisionError)
end
def test_exception_handler_does_reraise_if_it_returns_true
exception = nil
assert_raises(ZeroDivisionError) do
Template.parse("{{ 1 | divided_by: 0 }}").render({}, exception_handler: ->(e) { exception = e; true })
end
assert exception.is_a?(ZeroDivisionError)
end
end