Define some Expectation methods

This commit is contained in:
Michael Miller 2018-10-01 20:34:26 -06:00
parent 3035273e9a
commit 4c2f6157af
2 changed files with 21 additions and 1 deletions

View file

@ -1,4 +1,11 @@
module Spectator::Expectations
abstract class Expectation
getter? negated : Bool
private def initialize(@negated)
end
abstract def eval : Bool
abstract def message : String
end
end

View file

@ -1,6 +1,19 @@
require "./expectation"
module Spectator::Expectations
class ValueExpectation < Expectation
class ValueExpectation(ActualType, ExpectedType) < Expectation
def initialize(negated,
@partial : ValueExpectationPartial(ActualType),
@matcher : ValueMatcher(ExpectedType))
super(negated)
end
def eval : Bool
@matcher.match?(@partial) ^ negated?
end
def message : String
negated? ? @matcher.negated_message(@partial) : @matcher.message(@partial)
end
end
end