Class: Sus::Have::Any

Inherits:
Object
  • Object
show all
Defined in:
lib/sus/have/any.rb

Instance Method Summary collapse

Constructor Details

#initialize(predicates) ⇒ Any

Returns a new instance of Any.



9
10
11
# File 'lib/sus/have/any.rb', line 9

def initialize(predicates)
	@predicates = predicates
end

Instance Method Details

#call(assertions, subject) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sus/have/any.rb', line 28

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


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sus/have/any.rb', line 13

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