Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 79be9b3

Browse files
committed
Number the failures
- also only count failures, not errors
1 parent b6503a2 commit 79be9b3

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

lib/rspec/core/formatters/documentation_formatter.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,12 @@ def example_finished(example)
4444
end
4545

4646
def failure_output(example, exception)
47-
expectation_not_met = exception.is_a?(::RSpec::Expectations::ExpectationNotMetError)
48-
49-
message = if expectation_not_met
50-
"#{current_indentation}#{example.description} (FAILED)"
51-
else
52-
"#{current_indentation}#{example.description} (ERROR)"
53-
end
47+
red("#{current_indentation}#{example.description} (FAILED - #{next_failure_index})")
48+
end
5449

55-
expectation_not_met ? red(message) : magenta(message)
50+
def next_failure_index
51+
@next_failure_index ||= 0
52+
@next_failure_index += 1
5653
end
5754

5855
def passed_output(example)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require "spec_helper"
2+
3+
module RSpec::Core::Formatters
4+
describe DocumentationFormatter do
5+
it "numbers the failures" do
6+
7+
examples = [
8+
double("example 1",
9+
:description => "first example",
10+
:execution_result => {:status => 'failed', :exception_encountered => Exception.new }
11+
),
12+
double("example 2",
13+
:description => "second example",
14+
:execution_result => {:status => 'failed', :exception_encountered => Exception.new }
15+
)
16+
]
17+
18+
output = StringIO.new
19+
RSpec.configuration.stub(:output) { output }
20+
RSpec.configuration.stub(:color_enabled?) { false }
21+
22+
formatter = DocumentationFormatter.new
23+
24+
examples.each {|e| formatter.example_finished(e) }
25+
26+
output.string.should =~ /first example \(FAILED - 1\)/m
27+
output.string.should =~ /second example \(FAILED - 2\)/m
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)