Class: Sus::Be::Or
- Inherits:
-
Object
- Object
- Sus::Be::Or
- Defined in:
- lib/sus/be.rb
Instance Method Summary collapse
- #&(other) ⇒ Object
- #call(assertions, subject) ⇒ Object
-
#initialize(predicates) ⇒ Or
constructor
A new instance of Or.
- #print(output) ⇒ Object
- #|(other) ⇒ Object
Constructor Details
#initialize(predicates) ⇒ Or
Returns a new instance of Or.
39 40 41 |
# File 'lib/sus/be.rb', line 39 def initialize(predicates) @predicates = predicates end |
Instance Method Details
#call(assertions, subject) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sus/be.rb', line 53 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 |
#print(output) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/sus/be.rb', line 43 def print(output) @predicates.each_with_index do |predicate, index| if index > 0 output.write(" or ", :reset) end predicate.print(output) end end |