lib/cased/test_helper.rb
def cased_events_with(expected_event = {})
      return cased_events.dup if expected_event.nil?

      if expected_event.empty?
        raise ArgumentError, 'You must call cased_events_with with a non empty Hash otherwise it will match all events'
      end

      expanded_expected_event = Cased::Context::Expander.expand(expected_event)
      if expanded_expected_event.empty?
        raise ArgumentError, <<~MSG.strip
          cased_events_with would have matched any published Cased event.

          cased_events_with was called with #{expected_event.inspect} but resulted into #{expanded_expected_event} after it was expanded.

          This typically happens when an object that includes Cased::Model does not implement either the #cased_id or #to_s method.
        MSG
      end

      # We need to normalize input as it could be a mix of strings and symbols.
      expected_event.deep_symbolize_keys!
      expanded_expected_event = expanded_expected_event.to_a

      events = cased_events.dup.collect(&:deep_symbolize_keys).collect(&:to_a)
      matching_events = events.select do |event|
        diff = expanded_expected_event - event
        diff.empty?
      end

      matching_events.collect(&:to_h)
    end
# Locates all published events matching a particular shape.
#
# @param expected_event [Hash] the shape of event expected to be published to Cased
#
# @example Simple hash
#   cased_events_with(action: 'user.login') # => [{ action: 'user.login', actor: 'garrett@cased.com' }, { action: 'user.login', actor: 'ted@cased.com' }]
#
# @example Nested hash
#   cased_events_with(issues: [{ issue_id: 1 }]) # => [{ action: 'user.login', issues: [{ issue_id: 1 }, { issue_id: 2 }]}]
#
# @example Cased::Model value hash
#   user = User.new
#   user.cased_context # => { user: 'garrett@cased.com', user_id: 'user_1234' }
#   cased_events_with(user: user) # => [{ user: 'garrett@cased.com', user_id: 'user_1234' }]
#
# @return [Array<Hash>] Array of matching published Cased events.
# @raises [ArgumentError] if expected_event is empty.
Locates all published events matching a particular shape.
Locates all published events matching a particular shape .
def cased_events_with(expected_event = {})
      return cased_events.dup if expected_event.nil?
      if expected_event.empty?
        raise ArgumentError, 'You must call cased_events_with with a non empty Hash otherwise it will match all events'
      end
      expanded_expected_event = Cased::Context::Expander.expand(expected_event)
      if expanded_expected_event.empty?
        raise ArgumentError, <<~MSG.strip
          cased_events_with would have matched any published Cased event.
          cased_events_with was called with #{expected_event.inspect} but resulted into #{expanded_expected_event} after it was expanded.
          This typically happens when an object that includes Cased::Model does not implement either the #cased_id or #to_s method.
        MSG
      end
      expected_event.deep_symbolize_keys!
      expanded_expected_event = expanded_expected_event.to_a
      events = cased_events.dup.collect(&:deep_symbolize_keys).collect(&:to_a)
      matching_events = events.select do |event|
        diff = expanded_expected_event - event
        diff.empty?
      end
      matching_events.collect(&:to_h)
    end
def cased_events_with ( expected_event = { } ) return cased_events . dup if expected_event . nil? if expected_event . empty? raise ArgumentError , 'You must call cased_events_with with a non empty Hash otherwise it will match all events' end expanded_expected_event = Cased :: Context :: Expander . expand ( expected_event ) if expanded_expected_event . empty? raise ArgumentError , <<~MSG . strip 
          cased_events_with would have matched any published Cased event.

          cased_events_with was called with  #{ expected_event . inspect }  but resulted into  #{ expanded_expected_event }  after it was expanded.

          This typically happens when an object that includes Cased::Model does not implement either the #cased_id or #to_s method.
         MSG end expected_event . deep_symbolize_keys! expanded_expected_event = expanded_expected_event . to_a events = cased_events . dup . collect ( & :deep_symbolize_keys ) . collect ( & :to_a ) matching_events = events . select do | event | diff = expanded_expected_event - event diff . empty? end matching_events . collect ( & :to_h ) end
Locates all published events matching a particular shape.
Locates all published events matching a particular shape .
# We need to normalize input as it could be a mix of strings and symbols.
Array of matching published Cased events.
Array of matching published Cased events .
Array<Hash>
[ArgumentError] if expected_event is empty.
[ ArgumentError ] if expected_event is empty .
expected_event
the shape of event expected to be published to Cased
the shape of event expected to be published to Cased
example
Simple hash cased_events_with(action: 'user.login') # => [{ action: 'user.login', actor: 'garrett@cased.com' }, { action: 'user.login', actor: 'ted@cased.com' }]
Simple hash cased_events_with ( action : ' user . login ' ) # = > [ { action : ' user . login ' actor : ' garrett@cased . com ' } { action : ' user . login ' actor : ' ted@cased . com ' } ]
example
Nested hash cased_events_with(issues: [{ issue_id: 1 }]) # => [{ action: 'user.login', issues: [{ issue_id: 1 }, { issue_id: 2 }]}]
Nested hash cased_events_with ( issues : [ { issue_id : 1 } ] ) # = > [ { action : ' user . login ' issues : [ { issue_id : 1 } { issue_id : 2 } ] } ]
example
None