5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/mail_assertions/asserts.rb', line 5
def assert_mail(conditions = {}, &block)
emails = list_with_conditions(ActionMailer::Base.deliveries, conditions)
unless emails.count == 1
all_subjects = ActionMailer::Base.deliveries.map(&:subject)
if emails.count == 0
assert false, "The mail '#{conditions}' was not sent: <#{all_subjects.join(', ')}>"
else
assert false, "More than one mail '#{conditions}' was sent: <#{all_subjects.join(', ')}>"
end
end
mail = emails.first
if block_given?
case block.arity
when 2
yield mail, mail.html_part.body.to_s
else
yield mail
end
end
end
|