class Stenotype::Test::Matchers::EventHasExpectedArguments

Attributes

expected_arguments[R]
matching_events[R]

Public Class Methods

new(matching_events, expected_arguments) click to toggle source
# File lib/stenotype/test/matchers.rb, line 29
def initialize(matching_events, expected_arguments)
  @matching_events = matching_events
  @expected_arguments = stringify_keys(expected_arguments)
end

Public Instance Methods

failure_message() click to toggle source
# File lib/stenotype/test/matchers.rb, line 40
def failure_message
  if multiple_events?
    "more than one event with given event name has been emitted. Can not match event arguments"
  else
    "expected to see all attributes from #{expected_arguments} to be included in event attributes but got #{matching_event}"
  end
end
matches?() click to toggle source
# File lib/stenotype/test/matchers.rb, line 34
def matches?
  return false if multiple_events?

  (expected_arguments.to_a - matching_event.to_a).empty?
end

Private Instance Methods

matching_event() click to toggle source
# File lib/stenotype/test/matchers.rb, line 54
def matching_event
  matching_events.first
end
multiple_events?() click to toggle source
# File lib/stenotype/test/matchers.rb, line 50
def multiple_events?
  matching_events.size > 1
end
stringify_keys(hash) click to toggle source
# File lib/stenotype/test/matchers.rb, line 58
def stringify_keys(hash)
  hash.transform_keys(&:to_s)
end