Sha256: 13c0029888c68de845343aca839ed24d564e7457a4fa34626c59977169130e35

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module AbstractNotifier
  module TestHelper
    def assert_notifications_sent(count, params)
      yield
      assert_equal deliveries.count, count
      count.times do |i|
        delivery = deliveries[0 - i]
        msg = message(msg) { "Expected #{mu_pp(delivery)} to include #{mu_pp(params)}" }
        assert hash_include?(delivery, params), msg
      end
    end

    def assert_notifications_enqueued(count, params)
      yield
      assert_equal enqueued_deliveries.count, count
      count.times do |i|
        delivery = enqueued_deliveries[0 - i]
        msg = message(msg) { "Expected #{mu_pp(delivery)} to include #{mu_pp(params)}" }
        assert hash_include?(delivery, params), msg
      end
    end

    private

    def deliveries
      AbstractNotifier::Testing::Driver.deliveries
    end

    def enqueued_deliveries
      AbstractNotifier::Testing::Driver.enqueued_deliveries
    end

    def hash_include?(haystack, needle)
      needle.all? do |k, v|
        haystack.key?(k) && haystack[k] == v
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
abstract_notifier-0.3.2 lib/abstract_notifier/testing/minitest.rb