shard-spectator/src/spectator/fail_result.cr

50 lines
1.2 KiB
Crystal
Raw Normal View History

2020-10-17 20:56:31 +00:00
require "./result"
module Spectator
# Outcome that indicates an example failed.
# This typically means an assertion did not pass.
class FailResult < Result
# Error that occurred while running the example.
# This describes the primary reason for the failure.
getter error : Exception
# Creates a failure result.
# The *elapsed* argument is the length of time it took to run the example.
# The *error* is the exception raised that caused the failure.
def initialize(elapsed, @error, expectations = [] of Expectation)
super(elapsed, expectations)
2020-10-17 20:56:31 +00:00
end
# Calls the `failure` method on *visitor*.
def accept(visitor)
visitor.fail
2020-10-17 20:56:31 +00:00
end
2021-01-31 02:42:46 +00:00
# Calls the `failure` method on *visitor*.
def accept(visitor)
visitor.fail(yield self)
2021-01-31 02:42:46 +00:00
end
# Indicates whether the example passed.
def pass? : Bool
false
end
# Indicates whether the example failed.
def fail? : Bool
true
end
2020-10-17 20:56:31 +00:00
# One-word description of the result.
def to_s(io)
io << "fail"
end
2021-01-31 02:42:46 +00:00
2021-01-31 03:07:36 +00:00
# Adds all of the JSON fields for finished results and failed results.
private def add_json_fields(json : ::JSON::Builder)
super
json.field("error", error.message)
2021-01-31 02:42:46 +00:00
end
2020-10-17 20:56:31 +00:00
end
end