Module: Pgbus::Testing::Assertions
- Included in:
- MinitestHelpers
- Defined in:
- lib/pgbus/testing/assertions.rb
Overview
Framework-agnostic assertion helpers. Included by both RSpec and Minitest integrations. Can also be included directly in any test class.
include Pgbus::Testing::Assertions
assert_pgbus_published(count: 1, routing_key: "orders.created") do
Order.create!(...)
end
Instance Method Summary collapse
- #assert_no_pgbus_published(routing_key: nil) ⇒ Object
- #assert_pgbus_published(count:, routing_key: nil) ⇒ Object
-
#perform_published_events ⇒ Object
Execute the block, capturing events, then dispatch all captured events to their registered handlers.
- #pgbus_published_events(routing_key: nil) ⇒ Object
Instance Method Details
#assert_no_pgbus_published(routing_key: nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pgbus/testing/assertions.rb', line 30 def assert_no_pgbus_published(routing_key: nil) before = pgbus_published_events(routing_key: routing_key).size yield after = pgbus_published_events(routing_key: routing_key).size actual = after - before return if actual.zero? suffix = routing_key ? " matching #{routing_key.inspect}" : "" raise_assertion("Expected no events published#{suffix}, got #{actual}") end |
#assert_pgbus_published(count:, routing_key: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pgbus/testing/assertions.rb', line 18 def assert_pgbus_published(count:, routing_key: nil) before = pgbus_published_events(routing_key: routing_key).size yield after = pgbus_published_events(routing_key: routing_key).size actual = after - before return if actual == count suffix = routing_key ? " matching #{routing_key.inspect}" : "" raise_assertion("Expected #{count} event(s) published#{suffix}, got #{actual}") end |