Module: ActiveDelivery::TestHelper

Defined in:
lib/active_delivery/testing/minitest.rb

Instance Method Summary collapse

Instance Method Details

#assert_deliveries(count) ⇒ Object



5
6
7
8
9
# File 'lib/active_delivery/testing/minitest.rb', line 5

def assert_deliveries(count)
  TestDelivery.enable { yield }

  assert_equal TestDelivery.store.count, count, "Expected #{count} deliveries, got #{TestDelivery.store.count}"
end

#assert_delivery_enqueued(delivery_class, event, count: 1, params: nil, with: nil) ⇒ Object



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
# File 'lib/active_delivery/testing/minitest.rb', line 13

def assert_delivery_enqueued(delivery_class, event, count: 1, params: nil, with: nil)
  TestDelivery.enable { yield }

  deliveries = TestDelivery.store

  if with
    args = with
    kwargs = args.pop if args.last.is_a?(Hash)
  end

  matching_deliveries, _unmatching_deliveries =
    deliveries.partition do |(delivery, options)|
      next false if delivery_class != delivery.owner.class

      next false if event != delivery.notification

      next false if params && !hash_include?(delivery.owner.params, params)

      next true unless with

      actual_args = delivery.params
      actual_kwargs = delivery.options

      next false unless args.each.with_index.all? do |arg, i|
        arg === actual_args[i]
      end

      next false unless kwargs.all? do |k, v|
        v === actual_kwargs[k]
      end

      true
    end

  assert_equal count, matching_deliveries.count, "Expected #{count} deliveries, got #{deliveries.count}"
end

#assert_no_deliveriesObject



11
# File 'lib/active_delivery/testing/minitest.rb', line 11

def assert_no_deliveries(&) = assert_deliveries(0, &)