Class: BrainzLab::Testing::EventExpectation
- Inherits:
-
Object
- Object
- BrainzLab::Testing::EventExpectation
- Defined in:
- lib/brainzlab/testing/helpers.rb
Overview
Fluent expectation builder for events
Instance Method Summary collapse
-
#failure_message ⇒ Object
Failure message for RSpec.
-
#failure_message_when_negated ⇒ Object
Negative failure message for RSpec.
-
#initialize(name, store) ⇒ EventExpectation
constructor
A new instance of EventExpectation.
-
#matching_events ⇒ Array<Hash>
Get matching events.
-
#satisfied? ⇒ Boolean
(also: #matches?)
Check if the expectation is satisfied.
-
#with(properties = {}) ⇒ self
Specify expected properties.
Constructor Details
#initialize(name, store) ⇒ EventExpectation
Returns a new instance of EventExpectation.
329 330 331 332 333 |
# File 'lib/brainzlab/testing/helpers.rb', line 329 def initialize(name, store) @name = name.to_s @store = store @expected_properties = {} end |
Instance Method Details
#failure_message ⇒ Object
Failure message for RSpec
368 369 370 371 372 373 374 375 |
# File 'lib/brainzlab/testing/helpers.rb', line 368 def if @expected_properties.empty? "expected event '#{@name}' to be tracked, but it wasn't" else "expected event '#{@name}' with properties #{@expected_properties.inspect} to be tracked, " \ "but got: #{@store.events_named(@name).map { |e| e[:properties] }.inspect}" end end |
#failure_message_when_negated ⇒ Object
Negative failure message for RSpec
378 379 380 381 382 383 384 |
# File 'lib/brainzlab/testing/helpers.rb', line 378 def if @expected_properties.empty? "expected event '#{@name}' not to be tracked, but it was" else "expected event '#{@name}' with properties #{@expected_properties.inspect} not to be tracked, but it was" end end |
#matching_events ⇒ Array<Hash>
Get matching events
360 361 362 363 364 365 |
# File 'lib/brainzlab/testing/helpers.rb', line 360 def matching_events events = @store.events_named(@name) return events if @expected_properties.empty? events.select { |e| properties_match?(e[:properties], @expected_properties) } end |
#satisfied? ⇒ Boolean Also known as: matches?
Check if the expectation is satisfied
349 350 351 |
# File 'lib/brainzlab/testing/helpers.rb', line 349 def satisfied? @store.event_tracked?(@name, @expected_properties.empty? ? nil : @expected_properties) end |
#with(properties = {}) ⇒ self
Specify expected properties
340 341 342 343 |
# File 'lib/brainzlab/testing/helpers.rb', line 340 def with(properties = {}) @expected_properties = properties self end |