1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
module Mocha
class ExpectationList
def initialize(expectations = [])
@expectations = expectations
end
def add(expectation)
@expectations.unshift(expectation)
expectation
end
def remove_all_matching_method(method_name)
@expectations.reject! { |expectation| expectation.matches_method?(method_name) }
end
def matches_method?(method_name)
@expectations.any? { |expectation| expectation.matches_method?(method_name) }
end
def match(invocation, ignoring_order: false)
matching_expectations(invocation, ignoring_order: ignoring_order).first
end
def match_but_out_of_order(invocation)
matching_expectations(invocation).first
end
def match_allowing_invocation(invocation)
matching_expectations(invocation).detect(&:invocations_allowed?)
end
def verified?(assertion_counter = nil)
@expectations.all? { |expectation| expectation.verified?(assertion_counter) }
end
def to_a
@expectations
end
def to_set
@expectations.to_set
end
def length
@expectations.length
end
def any?
@expectations.any?
end
def +(other)
self.class.new(to_a + other.to_a)
end
private
def matching_expectations(invocation, ignoring_order: false)
@expectations.select { |e| e.match?(invocation, ignoring_order: ignoring_order) }
end
end
end
|