2018-09-15 19:25:11 +00:00
|
|
|
require "./result"
|
2018-09-15 16:36:20 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
2021-06-10 04:15:15 +00:00
|
|
|
# Reason the example was skipped or marked pending.
|
|
|
|
getter reason : String
|
|
|
|
|
2021-07-17 22:25:32 +00:00
|
|
|
# Location the pending result was triggered from.
|
2021-07-17 22:34:15 +00:00
|
|
|
getter! location : Location
|
2021-07-17 22:25:32 +00:00
|
|
|
|
2020-10-17 20:56:31 +00:00
|
|
|
# Creates the result.
|
|
|
|
# *elapsed* is the length of time it took to run the example.
|
2021-06-10 04:15:15 +00:00
|
|
|
# A *reason* for the skip/pending result can be specified.
|
2021-07-17 22:25:32 +00:00
|
|
|
# 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)
|
2021-06-10 04:15:15 +00:00
|
|
|
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)
|
2021-05-16 18:19:16 +00:00
|
|
|
visitor.pending(self)
|
2019-02-17 21:24:02 +00:00
|
|
|
end
|
2019-03-23 02:12:36 +00:00
|
|
|
|
2021-01-31 02:42:46 +00:00
|
|
|
# Calls the `pending` method on the *visitor*.
|
2023-01-27 00:19:31 +00:00
|
|
|
def accept(visitor, &)
|
2021-01-31 02:42:46 +00:00
|
|
|
visitor.pending(yield self)
|
|
|
|
end
|
|
|
|
|
2021-05-13 03:39:50 +00:00
|
|
|
# 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.
|
2022-11-05 02:56:02 +00:00
|
|
|
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")
|
2021-06-10 04:15:15 +00:00
|
|
|
json.field("pending_message", @reason)
|
2021-06-03 04:48:48 +00:00
|
|
|
end
|
2018-09-15 16:36:20 +00:00
|
|
|
end
|
|
|
|
end
|