提交 20ad04e5 编写于 作者: G Genadi Samokovarov

Rename #source_extract to #source_extracts in ExceptionWrapper

It returns multiple source extracts since 1ed264bc. Also cleaned its
result structure, as we no longer need the file in a code extract.
上级 759054ab
...@@ -53,7 +53,7 @@ def render_exception(env, exception) ...@@ -53,7 +53,7 @@ def render_exception(env, exception)
show_source_idx: source_to_show_id, show_source_idx: source_to_show_id,
trace_to_show: trace_to_show, trace_to_show: trace_to_show,
routes_inspector: routes_inspector(exception), routes_inspector: routes_inspector(exception),
source_extract: wrapper.source_extract, source_extracts: wrapper.source_extracts,
line_number: wrapper.line_number, line_number: wrapper.line_number,
file: wrapper.file file: wrapper.file
) )
......
...@@ -81,13 +81,13 @@ def self.status_code_for_exception(class_name) ...@@ -81,13 +81,13 @@ def self.status_code_for_exception(class_name)
Rack::Utils.status_code(@@rescue_responses[class_name]) Rack::Utils.status_code(@@rescue_responses[class_name])
end end
def source_extract def source_extracts
backtrace.map do |trace| backtrace.map do |trace|
file, line = trace.split(":") file, line = trace.split(":")
line_number = line.to_i line_number = line.to_i
{ {
code: source_fragment(file, line_number), code: source_fragment(file, line_number),
file: file,
line_number: line_number line_number: line_number
} }
end end
......
<% @source_extract.each_with_index do |extract_source, index| %> <% @source_extracts.each_with_index do |source_extract, index| %>
<% if extract_source[:code] %> <% if source_extract[:code] %>
<div class="source <%="hidden" if @show_source_idx != index%>" id="frame-source-<%=index%>"> <div class="source <%="hidden" if @show_source_idx != index%>" id="frame-source-<%=index%>">
<div class="info"> <div class="info">
Extracted source (around line <strong>#<%= extract_source[:line_number] %></strong>): Extracted source (around line <strong>#<%= source_extract[:line_number] %></strong>):
</div> </div>
<div class="data"> <div class="data">
<table cellpadding="0" cellspacing="0" class="lines"> <table cellpadding="0" cellspacing="0" class="lines">
<tr> <tr>
<td> <td>
<pre class="line_numbers"> <pre class="line_numbers">
<% extract_source[:code].each_key do |line_number| %> <% source_extract[:code].each_key do |line_number| %>
<span><%= line_number -%></span> <span><%= line_number -%></span>
<% end %> <% end %>
</pre> </pre>
</td> </td>
<td width="100%"> <td width="100%">
<pre> <pre>
<% extract_source[:code].each do |line, source| -%><div class="line<%= " active" if line == extract_source[:line_number] -%>"><%= source -%></div><% end -%> <% source_extract[:code].each do |line, source| -%><div class="line<%= " active" if line == source_extract[:line_number] -%>"><%= source -%></div><% end -%>
</pre> </pre>
</td> </td>
</tr> </tr>
......
...@@ -25,13 +25,13 @@ def backtrace ...@@ -25,13 +25,13 @@ def backtrace
@environment = { 'action_dispatch.backtrace_cleaner' => cleaner } @environment = { 'action_dispatch.backtrace_cleaner' => cleaner }
end end
test '#source_extract fetches source fragments for every backtrace entry' do test '#source_extracts fetches source fragments for every backtrace entry' do
exception = TestError.new("lib/file.rb:42:in `index'") exception = TestError.new("lib/file.rb:42:in `index'")
wrapper = ExceptionWrapper.new({}, exception) wrapper = ExceptionWrapper.new({}, exception)
wrapper.expects(:source_fragment).with('lib/file.rb', 42).returns('foo') wrapper.expects(:source_fragment).with('lib/file.rb', 42).returns('foo')
assert_equal [ code: 'foo', file: 'lib/file.rb', line_number: 42 ], wrapper.source_extract assert_equal [ code: 'foo', line_number: 42 ], wrapper.source_extracts
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册