mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Capture expectations
This commit is contained in:
parent
14608c8b2d
commit
fab216419c
3 changed files with 45 additions and 5 deletions
28
spec/helpers/expectation.cr
Normal file
28
spec/helpers/expectation.cr
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Spectator::SpecHelpers
|
||||
# Information about an `expect` call in an example.
|
||||
struct Expectation
|
||||
# Indicates whether the expectation passed or failed.
|
||||
getter? satisfied : Bool
|
||||
|
||||
# Message when the expectation failed.
|
||||
# Only available when `#satisfied?` is false.
|
||||
getter! message : String
|
||||
|
||||
# Additional information about the expectation.
|
||||
# Only available when `#satisfied?` is false.
|
||||
getter! values : Hash(String, String)
|
||||
|
||||
# Creates the expectation outcome.
|
||||
def initialize(@satisfied, @message, @values)
|
||||
end
|
||||
|
||||
# Extracts the expectation information from a `JSON::Any` object.
|
||||
def self.from_json_any(object : JSON::Any)
|
||||
satisfied = object["satisfied"].as_bool
|
||||
message = object["failure"]?.try(&.as_s?)
|
||||
values = object["values"]?.try(&.as_h?)
|
||||
values = values.transform_values(&.as_s) if values
|
||||
new(satisfied, message, values)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue