Class: Stenotype::Test::Matchers::EventHasExpectedArguments

Inherits:
Object
  • Object
show all
Defined in:
lib/stenotype/test/matchers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matching_events, expected_arguments) ⇒ EventHasExpectedArguments

Returns a new instance of EventHasExpectedArguments.



29
30
31
32
# 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

Instance Attribute Details

#expected_argumentsObject (readonly)

Returns the value of attribute expected_arguments.



27
28
29
# File 'lib/stenotype/test/matchers.rb', line 27

def expected_arguments
  @expected_arguments
end

#matching_eventsObject (readonly)

Returns the value of attribute matching_events.



27
28
29
# File 'lib/stenotype/test/matchers.rb', line 27

def matching_events
  @matching_events
end

Instance Method Details

#failure_messageObject



40
41
42
43
44
45
46
# 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?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# 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