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
This commit is contained in:
David Heinemeier Hansson 2004-12-13 23:28:10 +00:00
parent 2c5a2e7f2e
commit aaf6956c47
2 changed files with 12 additions and 3 deletions

@ -1,5 +1,7 @@
*SVN*
* Added TemplateError#backtrace that makes it much easier to debug template errors from unit and functional tests
* Added display of error messages with scaffolded form pages
* Added option to ERB templates to swallow newlines by using <% if something -%> instead of just <% if something %>. Example:

@ -28,7 +28,7 @@ def sub_template_message
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 @@ def source_extract
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 @@ def to_s
"\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, "")