Module: ActiveDelivery::TestDelivery

Included in:
Base
Defined in:
lib/active_delivery/testing.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clearObject



29
30
31
# File 'lib/active_delivery/testing.rb', line 29

def clear
  store.clear
end

.enableObject

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
# File 'lib/active_delivery/testing.rb', line 6

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

.enabled?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/active_delivery/testing.rb', line 17

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

.storeObject



25
26
27
# File 'lib/active_delivery/testing.rb', line 25

def store
  @store ||= []
end

.track(delivery, event, args, options) ⇒ Object



21
22
23
# File 'lib/active_delivery/testing.rb', line 21

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

Instance Method Details

#notify(event, *args, **options) ⇒ Object



34
35
36
37
38
# File 'lib/active_delivery/testing.rb', line 34

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

#test?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/active_delivery/testing.rb', line 40

def test?
  TestDelivery.enabled?
end