Skip to content

Commit 97feeb4

Browse files
authored
Merge pull request rspec#2351 from rspec/errors_occured
Include error count for errors occurring outside examples in summary
2 parents 1ebd808 + 3eb500b commit 97feeb4

File tree

7 files changed

+33
-8
lines changed

7 files changed

+33
-8
lines changed

Changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### Development
2+
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.6.0.beta1...master)
3+
4+
Enhancements:
5+
6+
* Include count of errors occurring outside examples in default summaries.
7+
(#2351, Jon Rowe)
8+
19
### 3.6.0.beta1 / 2016-10-09
210
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.5.4...v3.6.0.beta1)
311

lib/rspec/core/notifications.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,12 @@ def fully_formatted
281281
# @attr pending_examples [Array<RSpec::Core::Example>] the pending examples
282282
# @attr load_time [Float] the number of seconds taken to boot RSpec
283283
# and load the spec files
284+
# @attr errors_outside_of_examples_count [Integer] the number of errors that
285+
# have occurred processing
286+
# the spec suite
284287
SummaryNotification = Struct.new(:duration, :examples, :failed_examples,
285-
:pending_examples, :load_time)
288+
:pending_examples, :load_time,
289+
:errors_outside_of_examples_count)
286290
class SummaryNotification
287291
# @api
288292
# @return [Fixnum] the number of examples run
@@ -308,6 +312,11 @@ def totals_line
308312
summary = Formatters::Helpers.pluralize(example_count, "example")
309313
summary << ", " << Formatters::Helpers.pluralize(failure_count, "failure")
310314
summary << ", #{pending_count} pending" if pending_count > 0
315+
if errors_outside_of_examples_count > 0
316+
summary << ", "
317+
summary << Formatters::Helpers.pluralize(errors_outside_of_examples_count, "error")
318+
summary << " occurred outside of examples"
319+
end
311320
summary
312321
end
313322

lib/rspec/core/reporter.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def initialize(configuration)
1818
@failed_examples = []
1919
@pending_examples = []
2020
@duration = @start = @load_time = nil
21+
@non_example_exception_count = 0
2122
end
2223

2324
# @private
@@ -157,6 +158,7 @@ def deprecation(hash)
157158
# Exceptions will be formatted the same way they normally are.
158159
def notify_non_example_exception(exception, context_description)
159160
@configuration.world.non_example_failure = true
161+
@non_example_exception_count += 1
160162

161163
example = Example.new(AnonymousExampleGroup, context_description, {})
162164
presenter = Formatters::ExceptionPresenter.new(exception, example, :indentation => 0)
@@ -177,7 +179,8 @@ def finish
177179
@profiler.example_groups)
178180
end
179181
notify :dump_summary, Notifications::SummaryNotification.new(@duration, @examples, @failed_examples,
180-
@pending_examples, @load_time)
182+
@pending_examples, @load_time,
183+
@non_example_exception_count)
181184
notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
182185
end
183186
end

spec/integration/spec_file_load_errors_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
8282
8383
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
84-
0 examples, 0 failures
84+
0 examples, 0 failures, 2 errors occurred outside of examples
8585
EOS
8686
end
8787
end

spec/integration/suite_hooks_errors_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def run_spec_expecting_non_zero(before_or_after)
6262
6363
6464
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
65-
0 examples, 0 failures
65+
0 examples, 0 failures, 1 error occurred outside of examples
6666
EOS
6767
end
6868

@@ -79,7 +79,7 @@ def run_spec_expecting_non_zero(before_or_after)
7979
8080
8181
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
82-
1 example, 0 failures
82+
1 example, 0 failures, 1 error occurred outside of examples
8383
EOS
8484
end
8585

@@ -126,7 +126,7 @@ def run_spec_expecting_non_zero(before_or_after)
126126
127127
128128
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
129-
0 examples, 0 failures
129+
0 examples, 0 failures, 3 errors occurred outside of examples
130130
EOS
131131
end
132132
end

spec/rspec/core/formatters/base_text_formatter_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
expect(formatter_output.string).to match("2 examples, 2 failures, 2 pending")
4141
end
4242

43+
it 'with errors includes that count' do
44+
send_notification :dump_summary, summary_notification(2, examples(2), examples(2), examples(2), 0, 3)
45+
expect(formatter_output.string).to match("2 examples, 2 failures, 2 pending, 3 errors occurred outside of examples")
46+
end
47+
4348
describe "rerun command for failed examples" do
4449
it "uses the location to identify the example" do
4550
line = __LINE__ + 2

spec/support/formatter_support.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ def failed_examples_notification
311311
::RSpec::Core::Notifications::ExamplesNotification.new reporter
312312
end
313313

314-
def summary_notification(duration, examples, failed, pending, time)
315-
::RSpec::Core::Notifications::SummaryNotification.new duration, examples, failed, pending, time
314+
def summary_notification(duration, examples, failed, pending, time, errors = 0)
315+
::RSpec::Core::Notifications::SummaryNotification.new duration, examples, failed, pending, time, errors
316316
end
317317

318318
def profile_notification(duration, examples, number)

0 commit comments

Comments
 (0)