Class: Sus::Be::Or

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

Instance Method Summary collapse

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

#&(other) ⇒ Object



69
70
71
# File 'lib/sus/be.rb', line 69

def &(other)
	And.new(self, other)
end

#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


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

#|(other) ⇒ Object



73
74
75
# File 'lib/sus/be.rb', line 73

def |(other)
	Or.new(@predicates + [other])
end