Integrate report and summary events

This commit is contained in:
Michael Miller 2021-05-16 13:20:02 -06:00
parent ceb368a7f4
commit 0ed684afbc
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
4 changed files with 37 additions and 11 deletions

View file

@ -96,17 +96,20 @@ module Spectator::Formatting
# Invoked after testing completes with a list of pending examples.
# This method will be called with an empty list if there were no pending (skipped) examples.
# Called after `#start_dump` and before `#dump_failures`.
# The *notification* will be an `ExampleSummaryNotification` type of object.
def dump_pending(_notification)
end
# Invoked after testing completes with a list of failed examples.
# This method will be called with an empty list if there were no failures.
# Called after `#dump_pending` and before `#dump_summary`.
# The *notification* will be an `ExampleSummaryNotification` type of object.
def dump_failures(_notification)
end
# Invoked after testing completes with summarized information from the test suite.
# Called after `#dump_failures` and before `#dump_profile`.
# The *notification* will be an `SummaryNotification` type of object.
def dump_summary(_notification)
end

View file

@ -1,7 +1,15 @@
require "../example"
module Spectator::Formatting
# Structure indicating the test suite has started.
record StartNotification, example_count : Int32
# Structure indicating an event occurred with an example.
record ExampleNotification, example : Example
# Structure containing a subset of examples from the test suite.
record ExampleSummaryNotification, examples : Enumerable(Example)
# Structure containing summarized information from the outcome of the test suite.
record SummaryNotification, report : Report
end

View file

@ -35,6 +35,22 @@ module Spectator
formatter.stop(nil)
end
# Triggers the 'dump' events.
private def summarize(report)
formatter.start_dump
notification = Formatting::ExampleSummaryNotification.new(report.pending)
formatter.dump_pending(notification)
notification = Formatting::ExampleSummaryNotification.new(report.failures)
formatter.dump_failures(notification)
notification = Formatting::SummaryNotification.new(report)
formatter.dump_summary(notification)
formatter.dump_profile(nil)
end
# Triggers the 'close' event.
# See `Formatting::Formatter#close`
private def close

View file

@ -1,4 +1,5 @@
require "../example"
require "../report"
require "../run_flags"
require "./events"
@ -26,11 +27,11 @@ module Spectator
# or false if there was at least one failure.
def run : Bool
start
executed = [] of Example
elapsed = Time.measure { executed = run_examples }
elapsed = Time.measure { run_examples }
stop
# TODO: Generate a report and pass it along to the formatter.
report = Report.generate(@examples, elapsed, nil) # TODO: Provide random seed.
summarize(report)
false # TODO: Report real result
@ -41,15 +42,12 @@ module Spectator
# Attempts to run all examples.
# Returns a list of examples that ran.
private def run_examples
Array(Example).new(example_count).tap do |executed|
@examples.each do |example|
result = run_example(example)
executed << example
@examples.each do |example|
result = run_example(example)
# Bail out if the example failed
# and configured to stop after the first failure.
break fail_fast if fail_fast? && result.fail?
end
# Bail out if the example failed
# and configured to stop after the first failure.
break fail_fast if fail_fast? && result.fail?
end
end
@ -58,6 +56,7 @@ module Spectator
private def run_example(example)
example_started(example)
result = if dry_run?
# TODO: Pending examples return a pending result instead of pass in RSpec dry-run.
dry_run_result
else
example.run