-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minitest assertions for RES #659
Comments
|
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 |
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 |
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 |
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 |
^^ that would be more of |
Let me throw following idea: assert_has_items(events_of_type(OrderPlaced), [
-> event {
assert_equal 1, event.data[:quantity]
},
]) where
|
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]
}
) |
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 |
In the meantime I've rebased and merged PR with initial gem. See it at: |
Gathering ideas and various implementations of assertions which help when working with RailsEventStore 👇
The text was updated successfully, but these errors were encountered: