Class: BrainzLab::Testing::Matchers::HaveBeenTrackedMatcher
- Inherits:
-
Object
- Object
- BrainzLab::Testing::Matchers::HaveBeenTrackedMatcher
- Defined in:
- lib/brainzlab/testing/matchers.rb
Overview
Matcher for events
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize ⇒ HaveBeenTrackedMatcher
constructor
A new instance of HaveBeenTrackedMatcher.
- #matches?(event_name) ⇒ Boolean
- #with(properties) ⇒ Object
Constructor Details
#initialize ⇒ HaveBeenTrackedMatcher
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
#description ⇒ Object
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_message ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/brainzlab/testing/matchers.rb', line 108 def 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_negated ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/brainzlab/testing/matchers.rb', line 122 def 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
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 |