Pass and output along reason for pending/skip result

This commit is contained in:
Michael Miller 2021-06-09 22:15:15 -06:00
parent 8d73434e0b
commit 5a2a71ffe8
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436
6 changed files with 17 additions and 9 deletions

View file

@ -26,7 +26,7 @@ module Spectator
# Result of the last time the example ran.
# Is pending if the example hasn't run.
getter result : Result = PendingResult.new
getter result : Result = PendingResult.new(Time::Span::ZERO, "Example not run")
# Creates the example.
# An instance to run the test code in is given by *context*.

View file

@ -78,8 +78,8 @@ module Spectator::Formatting::Components::JUnit
end
# Adds a skipped element to the test case node.
def pending(_result)
@xml.element("skipped") # TODO: Populate message attribute with reason from result.
def pending(result)
@xml.element("skipped", message: result.reason)
end
end
end

View file

@ -13,7 +13,7 @@ module Spectator::Formatting::Components
# Content displayed on the second line of the block after the label.
private def subtitle
"No reason given" # TODO: Get reason from result.
@result.reason
end
# Prefix for the second line of the block.

View file

@ -33,7 +33,11 @@ module Spectator::Formatting
# TODO: Skipped tests should report ok.
@io << "not ok " << @counter << " - "
@io << notification.example << " # TODO "
@io.puts "No reason given" # TODO: Get reason from result.
# This should never be false.
if (result = notification.example.result).responds_to?(:reason)
@io.puts result.reason
end
end
# Invoked after an example fails.

View file

@ -121,7 +121,7 @@ module Spectator
when ExpectationFailed
FailResult.new(elapsed, error, @expectations)
when ExamplePending
PendingResult.new(elapsed, @expectations)
PendingResult.new(elapsed, error.message || "No reason given", @expectations)
else
ErrorResult.new(elapsed, error, @expectations)
end

View file

@ -5,10 +5,14 @@ module Spectator
# A pending result means the example is not ready to run yet.
# This can happen when the functionality to be tested is not implemented yet.
class PendingResult < Result
# Reason the example was skipped or marked pending.
getter reason : String
# Creates the result.
# *elapsed* is the length of time it took to run the example.
def initialize(elapsed = Time::Span::ZERO, expectations = [] of Expectation)
super
# A *reason* for the skip/pending result can be specified.
def initialize(elapsed = Time::Span::ZERO, @reason = "No reason given", expectations = [] of Expectation)
super(elapsed, expectations)
end
# Calls the `pending` method on the *visitor*.
@ -40,7 +44,7 @@ module Spectator
def to_json(json : JSON::Builder)
super
json.field("status", "pending")
json.field("pending_message", "Not implemented") # TODO: Provide pending message.
json.field("pending_message", @reason)
end
end
end