Sha256: 54f7f18af25afeb4cc1f08a3699e16399431810584fb06b4b8e5373b98c88dbd

Contents?: true

Size: 1009 Bytes

Versions: 2

Compression:

Stored size: 1009 Bytes

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[:active_delivery_testing] = true
          yield
        ensure
          Thread.current[:active_delivery_testing] = false
        end
      end

      def enabled?
        Thread.current[: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

2 entries across 2 versions & 1 rubygems

Version Path
active_delivery-0.4.0 lib/active_delivery/testing.rb
active_delivery-0.3.1 lib/active_delivery/testing.rb