mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Remove sub-class and abstract base for Expectation
This was over-engineered and only the base class is needed.
This commit is contained in:
parent
46a6a4e51e
commit
1ce594051c
3 changed files with 14 additions and 37 deletions
|
@ -1,11 +1,14 @@
|
|||
module Spectator::Expectations
|
||||
abstract class Expectation
|
||||
class Expectation
|
||||
# Populates the base portiion of the expectation with values.
|
||||
# The `matched` flag should be true if the matcher is satisfied with the partial.
|
||||
# The `negated` flag should be true if the expectation is inverted.
|
||||
# These options are mutually-exclusive in this context.
|
||||
# Don't flip the value of `matched` because `negated` is true.
|
||||
def initialize(@matched : Bool, @negated : Bool)
|
||||
# The `partial` and the `matcher` arguments should reference
|
||||
# the actual and expected result respectively.
|
||||
def initialize(@matched : Bool, @negated : Bool,
|
||||
@partial : ExpectationPartial, @matcher : Matchers::Matcher)
|
||||
end
|
||||
|
||||
# Indicates whether the expectation was satisifed.
|
||||
|
@ -26,10 +29,14 @@ module Spectator::Expectations
|
|||
satisfied? ? message : negated_message
|
||||
end
|
||||
|
||||
# Describes the condition that must be met for the matcher to be satisifed.
|
||||
private abstract def message : String
|
||||
# Describes the condition that must be met for the expectation to be satisifed.
|
||||
private def message : String
|
||||
@matcher.message(@partial)
|
||||
end
|
||||
|
||||
# Describes the condition under which the matcher won't be satisifed.
|
||||
private abstract def negated_message : String
|
||||
# Describes the condition under which the expectation won't be satisifed.
|
||||
private def negated_message : String
|
||||
@matcher.negated_message(@partial)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
require "./expectation"
|
||||
|
||||
module Spectator::Expectations
|
||||
# Expectation that operates on values.
|
||||
# There is a primary "actual" value that the SUT produced.
|
||||
# A matcher is used on that value to determine whether it satisfies some criteria.
|
||||
class ValueExpectation(ActualType) < Expectation
|
||||
# Creates the expectation.
|
||||
# The `matched` flag should be true if the matcher is satisfied with the partial.
|
||||
# The `negated` flag should be true if the expectation is inverted.
|
||||
# See `Expectation#initialize` for details on these two arguments.
|
||||
# The `partial` and the `matcher` arguments should reference
|
||||
# the actual and expected value with matcher respectively.
|
||||
def initialize(matched, negated,
|
||||
@partial : ValueExpectationPartial(ActualType),
|
||||
@matcher : Matchers::Matcher)
|
||||
super(matched, negated)
|
||||
end
|
||||
|
||||
# Describes the condition that must be met for the expectation to be satisifed.
|
||||
private def message : String
|
||||
@matcher.message(@partial)
|
||||
end
|
||||
|
||||
# Describes the condition under which the expectation won't be satisifed.
|
||||
private def negated_message : String
|
||||
@matcher.negated_message(@partial)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -24,7 +24,7 @@ module Spectator::Expectations
|
|||
# Evaluates the expectation and returns it.
|
||||
private def eval(matcher, negated = false) : Expectation
|
||||
matched = matcher.match?(self)
|
||||
ValueExpectation.new(matched, negated, self, matcher)
|
||||
Expectation.new(matched, negated, self, matcher)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue