Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Enhancements:
the number of runs necessary to determine that an example set cannot be
minimized further. (Simon Coffey, #1997)

Bug Fixes:

* Fix formatters to handle exceptions for which `backtrace` returns `nil`.
(Myron Marston, #2023)

### 3.3.1 / 2015-06-18
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.3.0...v3.3.1)

Expand Down
8 changes: 6 additions & 2 deletions lib/rspec/core/formatters/exception_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def colorized_message_lines(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
end

def formatted_backtrace
backtrace_formatter.format_backtrace(exception.backtrace, example.metadata)
backtrace_formatter.format_backtrace(exception_backtrace, example.metadata)
end

def colorized_formatted_backtrace(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
Expand Down Expand Up @@ -129,7 +129,7 @@ def read_failed_line

def find_failed_line
example_path = example.metadata[:absolute_file_path].downcase
exception.backtrace.find do |line|
exception_backtrace.find do |line|
next unless (line_path = line[/(.+?):(\d+)(|:\d+)/, 1])
File.expand_path(line_path).downcase == example_path
end
Expand All @@ -147,6 +147,10 @@ def formatted_message_and_backtrace(colorizer, indentation)
formatted
end

def exception_backtrace
exception.backtrace || []
end

# @private
# Configuring the `ExceptionPresenter` with the right set of options to handle
# pending vs failed vs skipped and aggregated (or not) failures is not simple.
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/formatters/html_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def percent_done
# produced during the specs.
def extra_failure_content(failure)
RSpec::Support.require_rspec_core "formatters/snippet_extractor"
backtrace = failure.exception.backtrace.map do |line|
backtrace = (failure.exception.backtrace || []).map do |line|
RSpec.configuration.backtrace_formatter.backtrace_line(line)
end
backtrace.compact!
Expand Down
13 changes: 8 additions & 5 deletions spec/rspec/core/bisect/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,26 @@ def run_formatter_specs
run_formatter_specs
end

expect(results).to have_attributes(
:all_example_ids => %w[
aggregate_failures "checking results" do
expect(results.all_example_ids).to eq %w[
./spec/rspec/core/resources/formatter_specs.rb[1:1]
./spec/rspec/core/resources/formatter_specs.rb[2:1:1]
./spec/rspec/core/resources/formatter_specs.rb[2:2:1]
./spec/rspec/core/resources/formatter_specs.rb[3:1]
./spec/rspec/core/resources/formatter_specs.rb[4:1]
./spec/rspec/core/resources/formatter_specs.rb[5:1]
./spec/rspec/core/resources/formatter_specs.rb[5:2]
],
:failed_example_ids => %w[
./spec/rspec/core/resources/formatter_specs.rb[5:3:1]
]

expect(results.failed_example_ids).to eq %w[
./spec/rspec/core/resources/formatter_specs.rb[2:2:1]
./spec/rspec/core/resources/formatter_specs.rb[4:1]
./spec/rspec/core/resources/formatter_specs.rb[5:1]
./spec/rspec/core/resources/formatter_specs.rb[5:2]
./spec/rspec/core/resources/formatter_specs.rb[5:3:1]
]
)
end
end

describe "aborting the run early" do
Expand Down
2 changes: 2 additions & 0 deletions spec/rspec/core/formatters/documentation_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def execution_result(values)
|a failing spec with odd backtraces
| fails with a backtrace that has no file (FAILED - 3)
| fails with a backtrace containing an erb file (FAILED - 4)
| with a `nil` backtrace
| raises (FAILED - 5)
|
|#{expected_summary_output_for_example_specs}
EOS
Expand Down
30 changes: 22 additions & 8 deletions spec/rspec/core/formatters/html_formatted.html
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ <h1>RSpec Code Examples</h1>
<div id="div_group_1" class="example_group passed">
<dl style="margin-left: 0px;">
<dt id="example_group_1" class="passed">pending spec with no implementation</dt>
<script type="text/javascript">makeYellow('rspec-header');</script><script type="text/javascript">makeYellow('div_group_1');</script><script type="text/javascript">makeYellow('example_group_1');</script><script type="text/javascript">moveProgressBar('14.2');</script><dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not yet implemented)</span></dd>
<script type="text/javascript">makeYellow('rspec-header');</script><script type="text/javascript">makeYellow('div_group_1');</script><script type="text/javascript">makeYellow('example_group_1');</script><script type="text/javascript">moveProgressBar('12.5');</script><dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: Not yet implemented)</span></dd>
</dl>
</div>
<div id="div_group_2" class="example_group passed">
Expand All @@ -291,13 +291,13 @@ <h1>RSpec Code Examples</h1>
<div id="div_group_3" class="example_group passed">
<dl style="margin-left: 15px;">
<dt id="example_group_3" class="passed">with content that would fail</dt>
<script type="text/javascript">makeYellow('rspec-header');</script><script type="text/javascript">makeYellow('div_group_3');</script><script type="text/javascript">makeYellow('example_group_3');</script><script type="text/javascript">moveProgressBar('28.5');</script><dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: No reason given)</span></dd>
<script type="text/javascript">makeYellow('rspec-header');</script><script type="text/javascript">makeYellow('div_group_3');</script><script type="text/javascript">makeYellow('example_group_3');</script><script type="text/javascript">moveProgressBar('25.0');</script><dd class="example not_implemented"><span class="not_implemented_spec_name">is pending (PENDING: No reason given)</span></dd>
</dl>
</div>
<div id="div_group_4" class="example_group passed">
<dl style="margin-left: 15px;">
<dt id="example_group_4" class="passed">behaves like shared</dt>
<script type="text/javascript">makeRed('rspec-header');</script><script type="text/javascript">makeRed('div_group_4');</script><script type="text/javascript">makeRed('example_group_4');</script><script type="text/javascript">moveProgressBar('42.8');</script><dd class="example pending_fixed">
<script type="text/javascript">makeRed('rspec-header');</script><script type="text/javascript">makeRed('div_group_4');</script><script type="text/javascript">makeRed('example_group_4');</script><script type="text/javascript">moveProgressBar('37.5');</script><dd class="example pending_fixed">
<span class="failed_spec_name">is marked as pending but passes</span>
<span class="duration">n.nnnns</span>
<div class="failure" id="failure_1">
Expand All @@ -315,15 +315,15 @@ <h1>RSpec Code Examples</h1>
<div id="div_group_5" class="example_group passed">
<dl style="margin-left: 0px;">
<dt id="example_group_5" class="passed">passing spec</dt>
<script type="text/javascript">moveProgressBar('57.1');</script><dd class="example passed">
<script type="text/javascript">moveProgressBar('50.0');</script><dd class="example passed">
<span class="passed_spec_name">passes</span><span class="duration">n.nnnns</span>
</dd>
</dl>
</div>
<div id="div_group_6" class="example_group passed">
<dl style="margin-left: 0px;">
<dt id="example_group_6" class="passed">failing spec</dt>
<script type="text/javascript">makeRed('div_group_6');</script><script type="text/javascript">makeRed('example_group_6');</script><script type="text/javascript">moveProgressBar('71.4');</script><dd class="example failed">
<script type="text/javascript">makeRed('div_group_6');</script><script type="text/javascript">makeRed('example_group_6');</script><script type="text/javascript">moveProgressBar('62.5');</script><dd class="example failed">
<span class="failed_spec_name">fails</span>
<span class="duration">n.nnnns</span>
<div class="failure" id="failure_2">
Expand All @@ -346,7 +346,7 @@ <h1>RSpec Code Examples</h1>
<div id="div_group_7" class="example_group passed">
<dl style="margin-left: 0px;">
<dt id="example_group_7" class="passed">a failing spec with odd backtraces</dt>
<script type="text/javascript">makeRed('div_group_7');</script><script type="text/javascript">makeRed('example_group_7');</script><script type="text/javascript">moveProgressBar('85.7');</script><dd class="example failed">
<script type="text/javascript">makeRed('div_group_7');</script><script type="text/javascript">makeRed('example_group_7');</script><script type="text/javascript">moveProgressBar('75.0');</script><dd class="example failed">
<span class="failed_spec_name">fails with a backtrace that has no file</span>
<span class="duration">n.nnnns</span>
<div class="failure" id="failure_3">
Expand All @@ -355,7 +355,7 @@ <h1>RSpec Code Examples</h1>
<pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for (erb)</span></code></pre>
</div>
</dd>
<script type="text/javascript">moveProgressBar('100.0');</script><dd class="example failed">
<script type="text/javascript">moveProgressBar('87.5');</script><dd class="example failed">
<span class="failed_spec_name">fails with a backtrace containing an erb file</span>
<span class="duration">n.nnnns</span>
<div class="failure" id="failure_4">
Expand All @@ -366,7 +366,21 @@ <h1>RSpec Code Examples</h1>
</dd>
</dl>
</div>
<script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>n.nnnn seconds</strong>";</script><script type="text/javascript">document.getElementById('totals').innerHTML = "7 examples, 4 failures, 2 pending";</script>
<div id="div_group_8" class="example_group passed">
<dl style="margin-left: 15px;">
<dt id="example_group_8" class="passed">with a `nil` backtrace</dt>
<script type="text/javascript">makeRed('div_group_8');</script><script type="text/javascript">makeRed('example_group_8');</script><script type="text/javascript">moveProgressBar('100.0');</script><dd class="example failed">
<span class="failed_spec_name">raises</span>
<span class="duration">n.nnnns</span>
<div class="failure" id="failure_5">
<div class="message"><pre>boom</pre></div>
<div class="backtrace"><pre></pre></div>
<pre class="ruby"><code><span class="linenum">-1</span><span class="comment"># Couldn't get snippet for </span></code></pre>
</div>
</dd>
</dl>
</div>
<script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>n.nnnn seconds</strong>";</script><script type="text/javascript">document.getElementById('totals').innerHTML = "8 examples, 5 failures, 2 pending";</script>
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/formatters/progress_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
output.gsub!(/ +$/, '') # strip trailing whitespace

expect(output).to eq(<<-EOS.gsub(/^\s+\|/, ''))
|**F.FFF
|**F.FFFF
|
|#{expected_summary_output_for_example_specs}
EOS
Expand Down
8 changes: 8 additions & 0 deletions spec/rspec/core/resources/formatter_specs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,12 @@ def e.message

raise e
end

context "with a `nil` backtrace" do
it "raises" do
raise "boom"
end

after { |ex| ex.exception.set_backtrace(nil) }
end
end
16 changes: 14 additions & 2 deletions spec/support/formatter_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,21 @@ def expected_summary_output_for_example_specs
| Exception
| # /foo.html.erb:1:in `<main>': foo (RuntimeError)
|
| 5) a failing spec with odd backtraces with a `nil` backtrace raises
| Failure/Error: Unable to find matching line from backtrace
| RuntimeError:
| boom
|
|Finished in n.nnnn seconds (files took n.nnnn seconds to load)
|7 examples, 4 failures, 2 pending
|8 examples, 5 failures, 2 pending
|
|Failed examples:
|
|rspec ./spec/rspec/core/resources/formatter_specs.rb:4 # pending command with block format behaves like shared is marked as pending but passes
|rspec ./spec/rspec/core/resources/formatter_specs.rb:32 # failing spec fails
|rspec ./spec/rspec/core/resources/formatter_specs.rb:38 # a failing spec with odd backtraces fails with a backtrace that has no file
|rspec ./spec/rspec/core/resources/formatter_specs.rb:44 # a failing spec with odd backtraces fails with a backtrace containing an erb file
|rspec ./spec/rspec/core/resources/formatter_specs.rb:62 # a failing spec with odd backtraces with a `nil` backtrace raises
EOS
end
else
Expand Down Expand Up @@ -158,15 +164,21 @@ def expected_summary_output_for_example_specs
| Exception
| # /foo.html.erb:1:in `<main>': foo (RuntimeError)
|
| 5) a failing spec with odd backtraces with a `nil` backtrace raises
| Failure/Error: Unable to find matching line from backtrace
| RuntimeError:
| boom
|
|Finished in n.nnnn seconds (files took n.nnnn seconds to load)
|7 examples, 4 failures, 2 pending
|8 examples, 5 failures, 2 pending
|
|Failed examples:
|
|rspec ./spec/rspec/core/resources/formatter_specs.rb:4 # pending command with block format behaves like shared is marked as pending but passes
|rspec ./spec/rspec/core/resources/formatter_specs.rb:32 # failing spec fails
|rspec ./spec/rspec/core/resources/formatter_specs.rb:38 # a failing spec with odd backtraces fails with a backtrace that has no file
|rspec ./spec/rspec/core/resources/formatter_specs.rb:44 # a failing spec with odd backtraces fails with a backtrace containing an erb file
|rspec ./spec/rspec/core/resources/formatter_specs.rb:62 # a failing spec with odd backtraces with a `nil` backtrace raises
EOS
end
end
Expand Down