class Sus::Be::Or
def &(other)
def &(other) And.new(self, other) end
def call(assertions, subject)
def call(assertions, subject) assertions.nested(self) do |assertions| @predicates.each do |predicate| predicate.call(assertions, subject) end if assertions.passed.any? # At least one passed, so we don't care about failures: assertions.failed.clear else # Nothing passed, so we failed: assertions.assert(false, "could not find any matching predicate") end end end
def initialize(predicates)
def initialize(predicates) @predicates = predicates end
def print(output)
def print(output) @predicates.each_with_index do |predicate, index| if index > 0 output.write(" or ", :reset) end predicate.print(output) end end
def |(other)
def |(other) Or.new(@predicates + [other]) end