2017-07-23 11:36:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-09-24 21:42:01 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
|
|
|
|
class TemplateErrorTest < ActiveSupport::TestCase
|
|
|
|
def test_provides_original_message
|
2015-11-03 09:54:34 -05:00
|
|
|
error = begin
|
|
|
|
raise Exception.new("original")
|
|
|
|
rescue Exception
|
|
|
|
raise ActionView::Template::Error.new("test") rescue $!
|
|
|
|
end
|
|
|
|
|
2010-09-24 21:42:01 -04:00
|
|
|
assert_equal "original", error.message
|
|
|
|
end
|
|
|
|
|
2013-10-30 11:48:09 -04:00
|
|
|
def test_provides_original_backtrace
|
2015-11-03 09:54:34 -05:00
|
|
|
error = begin
|
|
|
|
original_exception = Exception.new
|
|
|
|
original_exception.set_backtrace(%W[ foo bar baz ])
|
|
|
|
raise original_exception
|
|
|
|
rescue Exception
|
|
|
|
raise ActionView::Template::Error.new("test") rescue $!
|
|
|
|
end
|
|
|
|
|
2013-10-30 11:48:09 -04:00
|
|
|
assert_equal %W[ foo bar baz ], error.backtrace
|
|
|
|
end
|
|
|
|
|
2010-09-24 21:42:01 -04:00
|
|
|
def test_provides_useful_inspect
|
2015-11-03 09:54:34 -05:00
|
|
|
error = begin
|
|
|
|
raise Exception.new("original")
|
|
|
|
rescue Exception
|
|
|
|
raise ActionView::Template::Error.new("test") rescue $!
|
|
|
|
end
|
|
|
|
|
2010-09-24 21:42:01 -04:00
|
|
|
assert_equal "#<ActionView::Template::Error: original>", error.inspect
|
|
|
|
end
|
2019-06-21 15:04:28 -04:00
|
|
|
|
|
|
|
def test_annotated_source_code_returns_empty_array_if_source_cant_be_found
|
|
|
|
template = Class.new do
|
|
|
|
def identifier
|
|
|
|
"something"
|
|
|
|
end
|
|
|
|
end.new
|
|
|
|
|
|
|
|
error = begin
|
|
|
|
raise
|
|
|
|
rescue
|
|
|
|
raise ActionView::Template::Error.new(template) rescue $!
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal [], error.annotated_source_code
|
|
|
|
end
|
2010-09-24 21:42:01 -04:00
|
|
|
end
|