Class: BrainzLab::Testing::Matchers::HaveBeenTrackedMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/brainzlab/testing/matchers.rb

Overview

Matcher for events

Instance Method Summary collapse

Constructor Details

#initializeHaveBeenTrackedMatcher

Returns a new instance of HaveBeenTrackedMatcher.



88
89
90
# File 'lib/brainzlab/testing/matchers.rb', line 88

def initialize
  @expected_properties = {}
end

Instance Method Details

#descriptionObject



131
132
133
134
135
# File 'lib/brainzlab/testing/matchers.rb', line 131

def description
  desc = "have tracked event '#{@event_name}'"
  desc += " with properties #{@expected_properties.inspect}" unless @expected_properties.empty?
  desc
end

#failure_messageObject



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/brainzlab/testing/matchers.rb', line 108

def failure_message
  actual_events = BrainzLab::Testing.event_store.events_named(@event_name)

  if actual_events.empty?
    "expected event '#{@event_name}' to have been tracked, but no such event was found.\n" \
      "Tracked events: #{BrainzLab::Testing.event_store.events.map { |e| e[:name] }.inspect}"
  else
    "expected event '#{@event_name}' to have been tracked with properties:\n" \
      "  #{@expected_properties.inspect}\n" \
      "but was tracked with:\n" \
      "  #{actual_events.map { |e| e[:properties] }.inspect}"
  end
end

#failure_message_when_negatedObject



122
123
124
125
126
127
128
129
# File 'lib/brainzlab/testing/matchers.rb', line 122

def failure_message_when_negated
  if @expected_properties.empty?
    "expected event '#{@event_name}' not to have been tracked, but it was"
  else
    "expected event '#{@event_name}' not to have been tracked with properties " \
      "#{@expected_properties.inspect}, but it was"
  end
end

#matches?(event_name) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
100
101
102
103
104
105
106
# File 'lib/brainzlab/testing/matchers.rb', line 97

def matches?(event_name)
  @event_name = event_name.to_s
  store = BrainzLab::Testing.event_store

  if @expected_properties.empty?
    store.event_tracked?(@event_name)
  else
    store.event_tracked?(@event_name, @expected_properties)
  end
end

#with(properties) ⇒ Object



92
93
94
95
# File 'lib/brainzlab/testing/matchers.rb', line 92

def with(properties)
  @expected_properties = properties
  self
end