mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Implement expectation results
This commit is contained in:
parent
297701c463
commit
7b8f47f327
2 changed files with 54 additions and 1 deletions
|
@ -24,5 +24,11 @@ module Spectator::Expectations
|
||||||
@results << result
|
@results << result
|
||||||
raise ExpectationFailed.new(result) if result.failure? && @raise_on_failure
|
raise ExpectationFailed.new(result) if result.failure? && @raise_on_failure
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the reported expectation results from the example.
|
||||||
|
# This should be run after the example has finished.
|
||||||
|
def results : ExpectationResults
|
||||||
|
ExpectationResults.new(@results.dup)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,53 @@
|
||||||
module Spectator::Expectations
|
module Spectator::Expectations
|
||||||
|
# Collection of results of expectations from an example.
|
||||||
class ExpectationResults
|
class ExpectationResults
|
||||||
def initialize(@results : Enumerable(ExpectationResult))
|
include Enumerable(Expectation::Result)
|
||||||
|
|
||||||
|
# Creates the collection.
|
||||||
|
def initialize(@results : Array(Expectation::Result))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Iterates through all expectation results.
|
||||||
|
def each
|
||||||
|
@results.each do |result|
|
||||||
|
yield result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a collection of only the successful expectation results.
|
||||||
|
def successes : Enumerable(Expectation::Result)
|
||||||
|
@results.select(&.successful?)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Iterates over only the successful expectation results.
|
||||||
|
def each_success
|
||||||
|
@results.each do |result|
|
||||||
|
yield result if result.successful?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a collection of only the failed expectation results.
|
||||||
|
def failures : Enumerables(Expectation::Result)
|
||||||
|
@results.select(&.failure?)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Iterates over only the failed expectation results.
|
||||||
|
def each_failure
|
||||||
|
@results.each do |result|
|
||||||
|
yield result if result.failure?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Determines whether the example was successful
|
||||||
|
# based on if all expectations were satisfied.
|
||||||
|
def successful?
|
||||||
|
@results.all?(&.successful?)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Determines whether the example failed
|
||||||
|
# based on if any expectations were not satisfied.
|
||||||
|
def failed?
|
||||||
|
@results.any?(&.failure?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue