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
|
# File 'lib/notify/test_helper.rb', line 5
def assert_notify_dispatched(name, count: nil, to: nil)
name = name.to_sym
matching = Notify.deliveries.select { |d| d[:name] == name }
if matching.empty?
delivered = Notify.deliveries.map { |d| d[:name] }.inspect
raise "Expected Notify.message(:#{name}) to have been dispatched, but it was not. " \
"Deliveries: #{delivered}"
end
if count && matching.size != count
raise "Expected #{count} dispatch(es) of :#{name}, got #{matching.size}"
end
if to
expected = Array(to)
all_recipients = matching.flat_map do |d|
(d[:resolved][:recipients] || {}).values.flatten
end
missing = expected - all_recipients
unless missing.empty?
raise "Expected recipients #{expected.inspect} for :#{name}, " \
"but #{missing.inspect} not found in resolved recipients: #{all_recipients.inspect}"
end
end
true
end
|