mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
More work hooking up expectations
This commit is contained in:
parent
b7ed4ec14c
commit
a8840351d5
2 changed files with 48 additions and 5 deletions
|
@ -11,6 +11,42 @@ module Spectator
|
||||||
# for instance using the *should* syntax or dynamically created expectations.
|
# for instance using the *should* syntax or dynamically created expectations.
|
||||||
getter source : Source?
|
getter source : Source?
|
||||||
|
|
||||||
|
# Indicates whether the expectation was met.
|
||||||
|
def satisfied?
|
||||||
|
@match_data.matched?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Indicates whether the expectation was not met.
|
||||||
|
def failed?
|
||||||
|
!satisfied?
|
||||||
|
end
|
||||||
|
|
||||||
|
# If nil, then the match was successful.
|
||||||
|
def failure_message?
|
||||||
|
@match_data.as?(Matchers::FailedMatchData).try(&.failure_message)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Description of why the match failed.
|
||||||
|
def failure_message
|
||||||
|
failure_message?.not_nil!
|
||||||
|
end
|
||||||
|
|
||||||
|
# Additional information about the match, useful for debug.
|
||||||
|
# If nil, then the match was successful.
|
||||||
|
def values?
|
||||||
|
@match_data.as?(Matchers::FailedMatchData).try(&.values)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Additional information about the match, useful for debug.
|
||||||
|
def values
|
||||||
|
values?.not_nil!
|
||||||
|
end
|
||||||
|
|
||||||
|
def description
|
||||||
|
@match_data.description
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# Creates the expectation.
|
# Creates the expectation.
|
||||||
# The *match_data* comes from the result of calling `Matcher#match`.
|
# The *match_data* comes from the result of calling `Matcher#match`.
|
||||||
# The *source* is the location of the expectation in source code, if available.
|
# The *source* is the location of the expectation in source code, if available.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require "./error_result"
|
require "./error_result"
|
||||||
|
require "./expectation"
|
||||||
require "./pass_result"
|
require "./pass_result"
|
||||||
require "./result"
|
require "./result"
|
||||||
|
|
||||||
|
@ -29,6 +30,8 @@ module Spectator
|
||||||
# Instead, methods the test calls can access it.
|
# Instead, methods the test calls can access it.
|
||||||
# For instance, an expectation reporting a result.
|
# For instance, an expectation reporting a result.
|
||||||
class Harness
|
class Harness
|
||||||
|
Log = ::Spectator::Log.for(self)
|
||||||
|
|
||||||
# Retrieves the harness for the current running example.
|
# Retrieves the harness for the current running example.
|
||||||
class_getter! current : self
|
class_getter! current : self
|
||||||
|
|
||||||
|
@ -56,8 +59,9 @@ module Spectator
|
||||||
translate(*outcome)
|
translate(*outcome)
|
||||||
end
|
end
|
||||||
|
|
||||||
def report(expectation)
|
def report(expectation : Expectation) : Nil
|
||||||
# TODO
|
Log.debug { "Reporting expectation #{expectation}" }
|
||||||
|
raise ExpectationFailed.new(expectation) if expectation.failed?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stores a block of code to be executed later.
|
# Stores a block of code to be executed later.
|
||||||
|
@ -84,10 +88,13 @@ module Spectator
|
||||||
# Takes the *elapsed* time and a possible *error* from the test.
|
# Takes the *elapsed* time and a possible *error* from the test.
|
||||||
# Returns a type of `Result`.
|
# Returns a type of `Result`.
|
||||||
private def translate(elapsed, error) : Result
|
private def translate(elapsed, error) : Result
|
||||||
if error
|
case error
|
||||||
ErrorResult.new(elapsed, error)
|
when nil
|
||||||
else
|
|
||||||
PassResult.new(elapsed)
|
PassResult.new(elapsed)
|
||||||
|
when ExpectationFailed
|
||||||
|
FailResult.new(elapsed, error)
|
||||||
|
else
|
||||||
|
ErrorResult.new(elapsed, error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue