Minitest assertions for RES #1867
Replies: 11 comments
-
|
Beta Was this translation helpful? Give feedback.
-
before-after-reject can probably be implemented with https://railseventstore.org/docs/subscribe/#temporary-subscriptions (and subscribe_to_all_events), also being a thread safe version by default |
Beta Was this translation helpful? Give feedback.
-
Using a bit older API: def assert_exact_new_events(event_store, new_events)
events_so_far = event_store.read_all_streams_forward
yield
assert_equal(
new_events,
(event_store.read_all_streams_forward - events_so_far).map(&:class)
)
end
def assert_new_events_include(event_store, expected_events)
events_so_far = event_store.read_all_streams_forward
yield
new_events = (event_store.read_all_streams_forward - events_so_far).map(&:class)
assert(
(expected_events - new_events).empty?,
"didn't include all of: #{expected_events} in #{(event_store.read_all_streams_forward - events_so_far).map(&:class)}"
)
end |
Beta Was this translation helpful? Give feedback.
-
def assert_items(actual_elements, expected_procs)
assert_equal(
expected_procs.length,
actual_elements.length,
"number of actual elements does not match expected"
)
actual_elements.zip(expected_procs) do |actual, expected|
expected.call(actual)
end
end |
Beta Was this translation helpful? Give feedback.
-
def assert_published(event_kind)
event = event_store.read.of_type(event_kind).last
assert_not_nil event
yield event
end
def assert_not_published(event_kind)
assert_nil event_store.read.of_type(event_kind).last
end |
Beta Was this translation helpful? Give feedback.
-
^^ that would be more of |
Beta Was this translation helpful? Give feedback.
-
Let me throw following idea: assert_has_items(events_of_type(OrderPlaced), [
-> event {
assert_equal 1, event.data[:quantity]
},
]) where
|
Beta Was this translation helpful? Give feedback.
-
Additionally above idea can be extended to operate within blocks assert_events_during do
perform_a_command
end.of_type(OrderPlaced).has_items(
-> event {
assert_equal 1, event.data[:quantity]
}
) |
Beta Was this translation helpful? Give feedback.
-
A few more samples from the wild: def assert_equal_event(expected, checked, verify_id: false)
if verify_id
assert_equal expected.event_id, checked.event_id
end
assert_equal expected.class, checked.class
assert_equal expected.data, checked.data
end
def assert_equal_events(expected, checked, verify_id: false)
assert_equal expected.size, checked.size
expected.zip(checked).each do |e, c|
assert_equal_event(e, c, verify_id: verify_id)
end
end
def assert_equal_unpublished_events(expected, model)
assert_equal_events(expected, model.unpublished_events)
end |
Beta Was this translation helpful? Give feedback.
-
In the meantime I've rebased and merged PR with initial gem. See it at: |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Gathering ideas and various implementations of assertions which help when working with RailsEventStore 👇
Beta Was this translation helpful? Give feedback.
All reactions