diff --git a/spec/helpers/spy_formatter.cr b/spec/helpers/spy_formatter.cr index 9afc644..394200e 100644 --- a/spec/helpers/spy_formatter.cr +++ b/spec/helpers/spy_formatter.cr @@ -28,7 +28,7 @@ class SpyFormatter < Spectator::Formatting::Formatter # Stores all invocatiosn made to `#end_suite`. # Each element is an invocation and the value is the arguments passed to the method. - getter end_suite_calls = [] of NamedTuple(report: Spectator::Report, profile: Bool) + getter end_suite_calls = [] of NamedTuple(report: Spectator::Report, profile: Spectator::Profile?) # Number of times the `#end_suite` method was called. def end_suite_call_count diff --git a/src/spectator/formatting/formatter.cr b/src/spectator/formatting/formatter.cr index ab85900..9efd800 100644 --- a/src/spectator/formatting/formatter.cr +++ b/src/spectator/formatting/formatter.cr @@ -14,8 +14,8 @@ module Spectator::Formatting # Called when a test suite finishes. # The results from the entire suite are provided. - # The *profile* flag is set to true when profiling results should be generated. - abstract def end_suite(report : Report, profile : Bool) + # The *profile* value is not nil when profiling results should be displayed. + abstract def end_suite(report : Report, profile : Profile?) # Called before a test starts. abstract def start_example(example : Example) diff --git a/src/spectator/formatting/json_formatter.cr b/src/spectator/formatting/json_formatter.cr index 6ab4d7f..a2bb26a 100644 --- a/src/spectator/formatting/json_formatter.cr +++ b/src/spectator/formatting/json_formatter.cr @@ -20,12 +20,12 @@ module Spectator::Formatting # Called when a test suite finishes. # The results from the entire suite are provided. - # The *profile* flag is set to true when profiling results should be generated. - def end_suite(report : Report, profile : Bool) + # The *profile* value is not nil when profiling results should be displayed. + def end_suite(report : Report, profile : Profile?) @json.end_array # examples totals(report) timing(report) - profile(report) if profile + profile(profile) if profile @json.field("result", report.failed? ? "fail" : "success") @json.end_object end @@ -66,7 +66,7 @@ module Spectator::Formatting end # Adds the profile information to the document. - private def profile(report) + private def profile(profile) raise NotImplementedError.new("profile") end end diff --git a/src/spectator/formatting/junit_formatter.cr b/src/spectator/formatting/junit_formatter.cr index 3215006..26a6a1a 100644 --- a/src/spectator/formatting/junit_formatter.cr +++ b/src/spectator/formatting/junit_formatter.cr @@ -24,8 +24,8 @@ module Spectator::Formatting # Called when a test suite finishes. # The results from the entire suite are provided. - # The *profile* flag does nothing for this formatter. - def end_suite(report : Report, profile : Bool) + # The *profile* value does nothing for this formatter. + def end_suite(report : Report, profile : Profile?) test_suites_block(report) @xml.end_document @xml.flush diff --git a/src/spectator/formatting/silent_formatter.cr b/src/spectator/formatting/silent_formatter.cr index eaf3464..2098480 100644 --- a/src/spectator/formatting/silent_formatter.cr +++ b/src/spectator/formatting/silent_formatter.cr @@ -9,7 +9,7 @@ module Spectator::Formatting # Called when a test suite finishes. # The results from the entire suite are provided. - def end_suite(report : Report, profile : Bool) + def end_suite(report : Report, profile : Profile?) # ... crickets ... end diff --git a/src/spectator/formatting/suite_summary.cr b/src/spectator/formatting/suite_summary.cr index c0e2e2e..be900f5 100644 --- a/src/spectator/formatting/suite_summary.cr +++ b/src/spectator/formatting/suite_summary.cr @@ -9,14 +9,14 @@ module Spectator::Formatting # Produces the summary of test suite from a report. # A block describing each failure is displayed. # At the end, the totals and runtime are printed. - # The *profile* flag is set to true when profiling results should be generated. - def end_suite(report, profile : Bool) + # The *profile* value is not nil when profiling results should be displayed. + def end_suite(report, profile : Profile?) if report.example_count > 0 @io.puts if is_a?(DotsFormatter) @io.puts end failures(report.failures) if report.failed_count > 0 - profile(report) if profile + profile(profile) if profile stats(report) remaining(report) if report.remaining? if report.failed? @@ -39,7 +39,7 @@ module Spectator::Formatting end # Produces the profiling section of the summary. - private def profile(report) + private def profile(profile) raise NotImplementedError.new("profile") end diff --git a/src/spectator/formatting/tap_formatter.cr b/src/spectator/formatting/tap_formatter.cr index eee6156..820098d 100644 --- a/src/spectator/formatting/tap_formatter.cr +++ b/src/spectator/formatting/tap_formatter.cr @@ -16,9 +16,10 @@ module Spectator::Formatting # Called when a test suite finishes. # The results from the entire suite are provided. - def end_suite(report : Report, profile : Bool) + # The *profile* value is not nil when profiling results should be displayed. + def end_suite(report : Report, profile : Profile?) @io.puts "Bail out!" if report.remaining? - profile(report) if profile + profile(profile) if profile end # Called before a test starts. @@ -32,8 +33,8 @@ module Spectator::Formatting @index += 1 end - # Generates profiling information for the report. - private def profile(report) + # Displays profiling information. + private def profile(profile) raise NotImplementedError.new("profile") end end diff --git a/src/spectator/runner.cr b/src/spectator/runner.cr index e00bba8..f61c2f7 100644 --- a/src/spectator/runner.cr +++ b/src/spectator/runner.cr @@ -24,7 +24,7 @@ module Spectator # Generate a report and pass it along to the formatter. remaining = @suite.size - results.size report = Report.new(results, elapsed, remaining, @config.fail_blank?) - @config.each_formatter(&.end_suite(report, @config.profile?)) + @config.each_formatter(&.end_suite(report, profile(report))) !report.failed? end @@ -66,5 +66,10 @@ module Spectator example_expectations = Expectations::ExampleExpectations.new(expectations) SuccessfulResult.new(example, Time::Span.zero, example_expectations) end + + # Generates and returns a profile if one should be displayed. + private def profile(report) + Profile.generate(report) if @config.profile? + end end end