mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Rename ExpectationRegistry to ExpectationReporter
Some initial implementation for the class.
This commit is contained in:
parent
e14babc014
commit
64a233a9e1
2 changed files with 28 additions and 26 deletions
|
@ -1,26 +0,0 @@
|
|||
module Spectator::Expectations
|
||||
# Tracks the expectations and their outcomes in an example.
|
||||
# A single instance of this class should be associated with one example.
|
||||
class ExpectationRegistry
|
||||
private getter? raise_on_failure : Bool
|
||||
|
||||
private def initialize(@raise_on_failure = true)
|
||||
end
|
||||
|
||||
def report(result : Expectation::Result) : Nil
|
||||
raise NotImplementedError.new("ExpectationRegistry#report")
|
||||
end
|
||||
|
||||
def self.current : ExpectationRegistry
|
||||
raise NotImplementedError.new("ExpectationRegistry.current")
|
||||
end
|
||||
|
||||
def self.start(example : Example) : Nil
|
||||
raise NotImplementedError.new("ExpectationRegistry.start")
|
||||
end
|
||||
|
||||
def self.finish : ExpectationResults
|
||||
raise NotImplementedError.new("ExpectationRegistry.finish")
|
||||
end
|
||||
end
|
||||
end
|
28
src/spectator/expectations/expectation_reporter.cr
Normal file
28
src/spectator/expectations/expectation_reporter.cr
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Spectator::Expectations
|
||||
# Tracks the expectations and their outcomes in an example.
|
||||
# A single instance of this class should be associated with one example.
|
||||
class ExpectationReporter
|
||||
# All results are stored in this array.
|
||||
# The initial capacity is set to one,
|
||||
# as that is the typical (and recommended)
|
||||
# number of expectations per example.
|
||||
@results = Array(Expectation::Result).new(1)
|
||||
|
||||
# Creates the reporter.
|
||||
# When the `raise_on_failure` flag is set to true,
|
||||
# which is the default, an exception will be raised
|
||||
# on the first failure that is reported.
|
||||
# To store failures and continue, set the flag to false.
|
||||
def initialize(@raise_on_failure = true)
|
||||
end
|
||||
|
||||
# Stores the outcome of an expectation.
|
||||
# If the raise on failure flag is set to true,
|
||||
# then this method will raise an exception
|
||||
# when a failing result is given.
|
||||
def report(result : Expectation::Result) : Nil
|
||||
@results << result
|
||||
raise ExpectationFailed.new(result) if result.failure? && @raise_on_failure
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue