Sha256: 8dbb05469218e700e44039b9407365fb8310f02133d04d30c763225fd05dcedc

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module ActiveDelivery
  module TestDelivery
    class << self
      def enable
        raise ArgumentError, "block is required" unless block_given?
        begin
          clear
          Thread.current.thread_variable_set(:active_delivery_testing, true)
          yield
        ensure
          Thread.current.thread_variable_set(:active_delivery_testing, false)
        end
      end

      def enabled?
        Thread.current.thread_variable_get(:active_delivery_testing) == true
      end

      def track(delivery, event, args, options)
        store << [delivery, event, args, options]
      end

      def store
        @store ||= []
      end

      def clear
        store.clear
      end
    end

    def notify(event, *args, **options)
      return super unless test?
      TestDelivery.track(self, event, args, options)
      nil
    end

    def test?
      TestDelivery.enabled?
    end
  end
end

ActiveDelivery::Base.prepend ActiveDelivery::TestDelivery

require "active_delivery/testing/rspec" if defined?(RSpec::Core)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_delivery-0.4.4 lib/active_delivery/testing.rb
active_delivery-0.4.3 lib/active_delivery/testing.rb
active_delivery-0.4.2 lib/active_delivery/testing.rb
active_delivery-0.4.1 lib/active_delivery/testing.rb