Class: Sus::Have::Any
- Inherits:
-
Object
- Object
- Sus::Have::Any
- Defined in:
- lib/sus/have/any.rb
Overview
Represents a predicate that checks if the subject matches any of the given predicates.
Instance Method Summary collapse
-
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
-
#initialize(predicates) ⇒ Any
constructor
Initialize a new Any predicate.
-
#print(output) ⇒ Object
Print a representation of this predicate.
Constructor Details
#initialize(predicates) ⇒ Any
Initialize a new Any predicate.
12 13 14 |
# File 'lib/sus/have/any.rb', line 12 def initialize(predicates) @predicates = predicates end |
Instance Method Details
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sus/have/any.rb', line 36 def call(assertions, subject) assertions.nested(self) do |assertions| @predicates.each do |predicate| predicate.call(assertions, subject) end if assertions.passed.any? # We don't care about any failures in this case, as long as one of the values passed: assertions.failed.clear else # Nothing passed, so we failed: assertions.assert(false, "could not find any matching value") end end end |
#print(output) ⇒ Object
Print a representation of this predicate.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sus/have/any.rb', line 18 def print(output) first = true output.write("have any {") @predicates.each do |predicate| if first first = false else output.write(", ") end output.write(predicate) end output.write("}") end |