Class: Sus::Have::Value
- Inherits:
-
Object
- Object
- Sus::Have::Value
- Defined in:
- lib/sus/have.rb
Overview
Represents a predicate that checks if a collection has a value matching a predicate.
Instance Method Summary collapse
-
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
-
#initialize(predicate) ⇒ Value
constructor
Initialize a new Value predicate.
-
#print(output) ⇒ Object
Print a representation of this predicate.
Constructor Details
#initialize(predicate) ⇒ Value
Initialize a new Value predicate.
78 79 80 |
# File 'lib/sus/have.rb', line 78 def initialize(predicate) @predicate = predicate end |
Instance Method Details
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/sus/have.rb', line 91 def call(assertions, subject) index = 0 subject.each do |value| # Capture the label (index and value) as a buffer of formatting # instructions, so the value is truncated/styled consistently: label = Output::Buffered.new label.write("[#{index}] = ") label.variable(value) assertions.nested(label, distinct: true) do |assertions| @predicate&.call(assertions, value) end index += 1 end end |
#print(output) ⇒ Object
Print a representation of this predicate.
84 85 86 |
# File 'lib/sus/have.rb', line 84 def print(output) output.write("value ", @predicate, :reset) end |