Module: ActiveEventStore::TestHelper

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_event_store/test_helper.rb,
lib/active_event_store/test_helper/event_published_matcher.rb

Defined Under Namespace

Classes: EventPublishedMatcher

Instance Method Summary collapse

Instance Method Details

#assert_async_event_subscriber_enqueued(subscriber_class, event: nil, queue: "events_subscribers", &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/active_event_store/test_helper.rb', line 50

def assert_async_event_subscriber_enqueued(subscriber_class, event: nil, queue: "events_subscribers", &block)
  subscriber_job = ActiveEventStore::SubscriberJob.for(subscriber_class)
  if subscriber_job.nil?
    fail("No such async subscriber: #{subscriber_class.name}")
  end

  expected_event = event
  event_matcher = ->(actual_event) { EventPublishedMatcher.event_matches?(expected_event, expected_event.data, actual_event) }

  expected_args = if expected_event
    event_matcher
  end

  assert_enqueued_with(job: subscriber_job, queue: queue, args: expected_args) do
    ActiveRecord::Base.transaction do
      block.call
    end
  end
end

#assert_event_published(expected_event, store: nil, with: nil, exactly: nil, at_least: nil, at_most: nil, &block) ⇒ Object

Asserts that the given event was published `exactly`, `at_least` or `at_most` number of times to a specific `store` `with` a particular hash of attributes.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_event_store/test_helper.rb', line 15

def assert_event_published(expected_event, store: nil, with: nil, exactly: nil, at_least: nil, at_most: nil, &block)
  matcher = EventPublishedMatcher.new(
    expected_event,
    store: store,
    with: with,
    exactly: exactly,
    at_least: at_least,
    at_most: at_most
  )

  if (msg = matcher.matches?(block))
    fail(msg)
  end

  matcher.matching_events
end

#refute_event_published(expected_event, store: nil, with: nil, exactly: nil, at_least: nil, at_most: nil, &block) ⇒ Object

Asserts that the given event was not published `exactly`, `at_least` or `at_most` number of times to a specific `store` `with` a particular hash of attributes.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/active_event_store/test_helper.rb', line 34

def refute_event_published(expected_event, store: nil, with: nil, exactly: nil, at_least: nil, at_most: nil, &block)
  matcher = EventPublishedMatcher.new(
    expected_event,
    store: store,
    with: with,
    exactly: exactly,
    at_least: at_least,
    at_most: at_most,
    refute: true
  )

  if (msg = matcher.matches?(block))
    fail(msg)
  end
end