lib/cased/test_helper.rb
def assert_cased_events(expected_event_count, expected_event_body = nil, &block)
      expected_event_body&.deep_symbolize_keys!

      actual_event_count = if block
        events_before_block = cased_events_with(expected_event_body)

        block&.call

        events_after_block = cased_events_with(expected_event_body)

        events_after_block.length - events_before_block.length
      else
        cased_events_with(expected_event_body).length
      end

      assert_equal expected_event_count, actual_event_count, "#{expected_event_count} Cased published events expected, but #{actual_event_count} were published"
    end
# Assertion that helps with testing that a number of events have been published to Cased.
#
# @param expected_event_count [Integer] The number of expected Cased events to be published.
# @param expected_event_body [Hash] Expected event to be published to Cased.
#
# @example Expected events with a filter inside of a block
#   def test_creates_user_create_event
#     assert_cased_events 1, action: 'user.create' do
#       create(:user)
#     end
#   end
#
# @example Expected events without a filter inside of a block
#   def test_creates_user_create_event
#     assert_cased_events 1 do
#       create(:user)
#     end
#   end
#
# @example Expected events with a filter for the duration of the test
#   def test_creates_user_create_event
#     create(:user)
#
#     assert_cased_events 1, action: 'user.create'
#   end
#
# @example Expected events without a filter for the duration of the test
#   def test_creates_user_create_event
#     create(:user)
#
#     assert_cased_events 1
#   end
#
# @example Cased::Model value hash
#   def test_creates_user_create_event
#     user = create(:user)
#
#     assert_cased_events 1, action: 'user.login', user: user
#   end
#
# @return [void]
Assertion that helps with testing that a number of events have been published to Cased.
Assertion that helps with testing that a number of events have been published to Cased .
def assert_cased_events(expected_event_count, expected_event_body = nil, &block)
      expected_event_body&.deep_symbolize_keys!
      actual_event_count = if block
        events_before_block = cased_events_with(expected_event_body)
        block&.call
        events_after_block = cased_events_with(expected_event_body)
        events_after_block.length - events_before_block.length
      else
        cased_events_with(expected_event_body).length
      end
      assert_equal expected_event_count, actual_event_count, "#{expected_event_count} Cased published events expected, but #{actual_event_count} were published"
    end
def assert_cased_events ( expected_event_count , expected_event_body = nil , & block ) expected_event_body &. deep_symbolize_keys! actual_event_count = if block events_before_block = cased_events_with ( expected_event_body ) block &. call events_after_block = cased_events_with ( expected_event_body ) events_after_block . length - events_before_block . length else cased_events_with ( expected_event_body ) . length end assert_equal expected_event_count , actual_event_count , "#{expected_event_count} Cased published events expected, but #{actual_event_count} were published" end
Assertion that helps with testing that a number of events have been published to Cased.
Assertion that helps with testing that a number of events have been published to Cased .
None
void
expected_event_count
The number of expected Cased events to be published.
The number of expected Cased events to be published .
expected_event_body
Expected event to be published to Cased.
Expected event to be published to Cased .
block
example
Expected events with a filter inside of a block def test_creates_user_create_event assert_cased_events 1, action: 'user.create' do create(:user) end end
Expected events with a filter inside of a block def test_creates_user_create_event assert_cased_events 1 action : ' user . create ' do create ( : user ) end end
example
Expected events without a filter inside of a block def test_creates_user_create_event assert_cased_events 1 do create(:user) end end
Expected events without a filter inside of a block def test_creates_user_create_event assert_cased_events 1 do create ( : user ) end end
example
Expected events with a filter for the duration of the test def test_creates_user_create_event create(:user) assert_cased_events 1, action: 'user.create' end
Expected events with a filter for the duration of the test def test_creates_user_create_event create ( : user ) assert_cased_events 1 action : ' user . create ' end
example
Expected events without a filter for the duration of the test def test_creates_user_create_event create(:user) assert_cased_events 1 end
Expected events without a filter for the duration of the test def test_creates_user_create_event create ( : user ) assert_cased_events 1 end
example
None