forked from eliotsykes/rails-testing-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ahoy_matchers.rb
23 lines (18 loc) · 852 Bytes
/
ahoy_matchers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require_relative 'matcher_extensions'
# Reminder: Relax or disable Ahoy's throttling in your test environment
# to avoid events being rejected. See Ahoy README section on throttling
# and/or Ahoy.throttle_limit/period settings.
RSpec::Matchers.define :have_tracked_event do |name, user: nil, **props|
supports_block_expectations
match_unless_raises do |interaction|
is_ahoy_ready_snippet = "typeof ahoy !== 'undefined' && ahoy !== null;"
RSpec::Wait.wait_for { evaluate_script(is_ahoy_ready_snippet) }.to eq true
relation = Ahoy::Event.where(name: name, user_id: user.try(:id))
props.each do |key, value|
relation = relation.where("properties ->> ? = ?", key, value)
end
RSpec::Wait.wait_for { relation.exists? }.to eq false
interaction.call
RSpec::Wait.wait_for { relation.exists? }.to eq true
end
end