Change formatters to take nillable profile

This commit is contained in:
Michael Miller 2019-03-25 16:05:38 -06:00
parent 6dd4c4bc2f
commit aabc25ad4f
8 changed files with 25 additions and 19 deletions

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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