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
|
# File 'lib/mail_checker/expectation_matcher.rb', line 5
def matches?(expectation)
attributes = {}
attributes['subject'] = expectation.subject if expectation.subject
attributes['sender'] = expectation.from if expectation.from
attributes['recipients'] = expectation.to if expectation.to
attributes.reverse_merge!(expectation.attributes) if expectation.attributes
@attributes = attributes
begin
Timeout::timeout(5) do
loop do
break if MailChecker::Mail.any? do |mail|
attributes.all? { |a, v| attribute_matches?([*mail.attributes[a]], to_regexp([*v])) }
end
sleep 0.5
end
end
rescue Timeout::Error
false
else
true
end
end
|