shard-spectator/src/spectator/pending_result.cr

58 lines
1.6 KiB
Crystal
Raw Normal View History

2018-09-15 19:25:11 +00:00
require "./result"
module Spectator
2018-11-16 16:48:35 +00:00
# Outcome that indicates running an example was pending.
# 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.
2018-09-15 19:25:11 +00:00
class PendingResult < Result
2021-06-12 00:59:10 +00:00
DEFAULT_REASON = "No reason given"
# Reason the example was skipped or marked pending.
getter reason : String
# Location the pending result was triggered from.
getter! location : Location
2020-10-17 20:56:31 +00:00
# Creates the result.
# *elapsed* is the length of time it took to run the example.
# A *reason* for the skip/pending result can be specified.
# If the pending result was triggered inside of an example, then *location* can be set.
def initialize(@reason = DEFAULT_REASON, @location = nil,
2021-07-17 22:55:43 +00:00
elapsed = Time::Span::ZERO, expectations = [] of Expectation)
super(elapsed, expectations)
2019-02-21 04:00:22 +00:00
end
2020-10-17 20:56:31 +00:00
# Calls the `pending` method on the *visitor*.
def accept(visitor)
visitor.pending(self)
end
2019-03-23 02:12:36 +00:00
2021-01-31 02:42:46 +00:00
# Calls the `pending` method on the *visitor*.
def accept(visitor, &)
2021-01-31 02:42:46 +00:00
visitor.pending(yield self)
end
# Indicates whether the example passed.
def pass? : Bool
false
end
# Indicates whether the example failed.
def fail? : Bool
false
end
2020-10-17 20:56:31 +00:00
# One-word description of the result.
def to_s(io : IO) : Nil
2019-03-23 02:12:36 +00:00
io << "pending"
end
2021-06-03 04:48:48 +00:00
# Creates a JSON object from the result information.
def to_json(json : JSON::Builder)
super
json.field("status", "pending")
json.field("pending_message", @reason)
2021-06-03 04:48:48 +00:00
end
end
end