From aaf6956c4776d6c43f77ab540cb51becdac3e00e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 13 Dec 2004 23:28:10 +0000 Subject: Added TemplateError#backtrace that makes it much easier to debug template errors from unit and functional tests git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@145 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/template_error.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_view/template_error.rb') diff --git a/actionpack/lib/action_view/template_error.rb b/actionpack/lib/action_view/template_error.rb index ab05b3303f..0ac8ee4c37 100644 --- a/actionpack/lib/action_view/template_error.rb +++ b/actionpack/lib/action_view/template_error.rb @@ -28,7 +28,7 @@ module ActionView end end - def source_extract + def source_extract(indention = 0) source_code = IO.readlines(@file_name) start_on_line = [ line_number - SOURCE_CODE_RADIUS - 1, 0 ].max @@ -37,9 +37,9 @@ module ActionView line_counter = start_on_line extract = source_code[start_on_line..end_on_line].collect do |line| line_counter += 1 - "#{line_counter}: " + line + "#{' ' * indention}#{line_counter}: " + line end - + extract.join end @@ -71,6 +71,13 @@ module ActionView "\n\n" end + def backtrace + [ + "On line ##{line_number} of #{file_name}\n\n#{source_extract(4)}\n " + + clean_backtrace(original_exception).join("\n ") + ] + end + private def strip_base_path(file_name) file_name.gsub(@base_path, "") -- cgit v1.2.3