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

Include error count for errors occurring outside examples in summary #2351

Merged
merged 4 commits into from
Nov 15, 2016
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
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### Development
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.6.0.beta1...master)

Enhancements:

* Include count of errors occurring outside examples in default summaries.
(#2351, Jon Rowe)

### 3.6.0.beta1 / 2016-10-09
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.5.4...v3.6.0.beta1)

Expand Down
11 changes: 10 additions & 1 deletion lib/rspec/core/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,12 @@ def fully_formatted
# @attr pending_examples [Array<RSpec::Core::Example>] the pending examples
# @attr load_time [Float] the number of seconds taken to boot RSpec
# and load the spec files
# @attr errors_outside_of_examples_count [Integer] the number of errors that
# have occurred processing
# the spec suite
SummaryNotification = Struct.new(:duration, :examples, :failed_examples,
:pending_examples, :load_time)
:pending_examples, :load_time,
:errors_outside_of_examples_count)
class SummaryNotification
# @api
# @return [Fixnum] the number of examples run
Expand All @@ -308,6 +312,11 @@ def totals_line
summary = Formatters::Helpers.pluralize(example_count, "example")
summary << ", " << Formatters::Helpers.pluralize(failure_count, "failure")
summary << ", #{pending_count} pending" if pending_count > 0
if errors_outside_of_examples_count > 0
summary << ", "
summary << Formatters::Helpers.pluralize(errors_outside_of_examples_count, "error")
summary << " occurred outside of examples"
end
summary
end

Expand Down
5 changes: 4 additions & 1 deletion lib/rspec/core/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(configuration)
@failed_examples = []
@pending_examples = []
@duration = @start = @load_time = nil
@non_example_exception_count = 0
end

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

example = Example.new(AnonymousExampleGroup, context_description, {})
presenter = Formatters::ExceptionPresenter.new(exception, example, :indentation => 0)
Expand All @@ -177,7 +179,8 @@ def finish
@profiler.example_groups)
end
notify :dump_summary, Notifications::SummaryNotification.new(@duration, @examples, @failed_examples,
@pending_examples, @load_time)
@pending_examples, @load_time,
@non_example_exception_count)
notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/spec_file_load_errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@


Finished in n.nnnn seconds (files took n.nnnn seconds to load)
0 examples, 0 failures
0 examples, 0 failures, 2 errors occurred outside of examples
EOS
end
end
6 changes: 3 additions & 3 deletions spec/integration/suite_hooks_errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def run_spec_expecting_non_zero(before_or_after)


Finished in n.nnnn seconds (files took n.nnnn seconds to load)
0 examples, 0 failures
0 examples, 0 failures, 1 error occurred outside of examples
EOS
end

Expand All @@ -79,7 +79,7 @@ def run_spec_expecting_non_zero(before_or_after)


Finished in n.nnnn seconds (files took n.nnnn seconds to load)
1 example, 0 failures
1 example, 0 failures, 1 error occurred outside of examples
EOS
end

Expand Down Expand Up @@ -126,7 +126,7 @@ def run_spec_expecting_non_zero(before_or_after)


Finished in n.nnnn seconds (files took n.nnnn seconds to load)
0 examples, 0 failures
0 examples, 0 failures, 3 errors occurred outside of examples
EOS
end
end
5 changes: 5 additions & 0 deletions spec/rspec/core/formatters/base_text_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
expect(formatter_output.string).to match("2 examples, 2 failures, 2 pending")
end

it 'with errors includes that count' do
send_notification :dump_summary, summary_notification(2, examples(2), examples(2), examples(2), 0, 3)
expect(formatter_output.string).to match("2 examples, 2 failures, 2 pending, 3 errors occurred outside of examples")
end

describe "rerun command for failed examples" do
it "uses the location to identify the example" do
line = __LINE__ + 2
Expand Down
4 changes: 2 additions & 2 deletions spec/support/formatter_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ def failed_examples_notification
::RSpec::Core::Notifications::ExamplesNotification.new reporter
end

def summary_notification(duration, examples, failed, pending, time)
::RSpec::Core::Notifications::SummaryNotification.new duration, examples, failed, pending, time
def summary_notification(duration, examples, failed, pending, time, errors = 0)
::RSpec::Core::Notifications::SummaryNotification.new duration, examples, failed, pending, time, errors
end

def profile_notification(duration, examples, number)
Expand Down