Skip to content

Commit

Permalink
Combine report_failures and report_pending into report_results
Browse files Browse the repository at this point in the history
  • Loading branch information
icy-arctic-fox committed Jul 28, 2024
1 parent ad4d600 commit 8a1105f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
28 changes: 11 additions & 17 deletions src/spectator/core/runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,19 @@ module Spectator
def run(spec : ExampleGroup)
report &.started
report &.suite_started
failures = [] of ExecutionResult
pending = [] of ExecutionResult
examples_to_run(spec).each do |example|
if (group = example.group) && group.no_runs?
report &.example_group_started(group)
results =
examples_to_run(spec).map do |example|
if (group = example.group) && group.no_runs?
report &.example_group_started(group)
end
result = run_example(example)
if (group = example.group) && group.run?
report &.example_group_finished(group)
end
result
end
result = run_example(example)
if result.failed?
failures << result
elsif result.skipped?
pending << result
end
if (group = example.group) && group.run?
report &.example_group_finished(group)
end
end
report &.suite_finished
report &.report_failures(failures) unless failures.empty?
report &.report_pending(pending) unless pending.empty?
report &.report_results(results)
report &.report_profile
report &.report_summary
report &.report_post_summary
Expand Down
17 changes: 12 additions & 5 deletions src/spectator/formatters/common_text_output.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ require "../core/source_cache"

module Spectator::Formatters
module CommonTextOutput
def report_failures(results : Enumerable(Core::ExecutionResult)) : Nil
def report_results(results : Enumerable(Core::ExecutionResult)) : Nil
failures = results.select &.failed?
report_failures(failures) unless failures.empty?
skipped = results.select &.skipped?
report_skipped(skipped) unless skipped.empty?
end

private def report_failures(results : Enumerable(Core::ExecutionResult)) : Nil
puts
puts "Failures:"
puts
Expand Down Expand Up @@ -83,17 +90,17 @@ module Spectator::Formatters
end
end

def report_pending(results : Enumerable(Core::ExecutionResult)) : Nil
private def report_skipped(results : Enumerable(Core::ExecutionResult)) : Nil
puts
puts "Pending:"
puts "Skipped:"
puts
padding = results.size.to_s.size - 1 # -1 since the minimum width is 1.
results.each_with_index(1) do |result, index|
print_pending(result, index, padding)
print_skipped(result, index, padding)
end
end

private def print_pending(result, number, padding) : Nil
private def print_skipped(result, number, padding) : Nil
end

def report_profile : Nil
Expand Down
5 changes: 1 addition & 4 deletions src/spectator/formatters/compatible_junit_formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ module Spectator::Formatters
parts.join('.')
end

def report_failures(results : Enumerable(Core::ExecutionResult)) : Nil
end

def report_pending(results : Enumerable(Core::ExecutionResult)) : Nil
def report_results(results : Enumerable(Core::ExecutionResult)) : Nil
end

def report_profile : Nil
Expand Down
4 changes: 1 addition & 3 deletions src/spectator/formatters/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ module Spectator::Formatters

abstract def example_finished(result : Core::ExecutionResult) : Nil

abstract def report_failures(results : Enumerable(Core::ExecutionResult)) : Nil

abstract def report_pending(results : Enumerable(Core::ExecutionResult)) : Nil
abstract def report_results(results : Enumerable(Core::ExecutionResult)) : Nil

abstract def report_profile : Nil

Expand Down

0 comments on commit 8a1105f

Please sign in to comment.