Class: Sus::Have::Value

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(predicate) ⇒ Value

Initialize a new Value predicate.



75
76
77
# File 'lib/sus/have.rb', line 75

def initialize(predicate)
	@predicate = predicate
end

Instance Method Details

#call(assertions, subject) ⇒ Object

Evaluate this predicate against a subject.



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/sus/have.rb', line 88

def call(assertions, subject)
	index = 0
	
	subject.each do |value|
		assertions.nested("[#{index}] = #{value.inspect}", distinct: true) do |assertions|
			@predicate&.call(assertions, value)
		end
		
		index += 1
	end
end

Print a representation of this predicate.



81
82
83
# File 'lib/sus/have.rb', line 81

def print(output)
	output.write("value ", @predicate, :reset)
end