Module: PlanMyStuff::TestHelpers::Notifications
- Defined in:
- lib/plan_my_stuff/test_helpers.rb
Overview
Captures plan_my_stuff.* ActiveSupport::Notifications events fired inside the given block. Lets consuming apps assert that their code triggers gem events without threading subscriptions through every spec.
Usage:
events = PlanMyStuff::TestHelpers::Notifications.capture do
PlanMyStuff::Issue.create!(...)
end
events.first[:name] # => "plan_my_stuff.issue.created"
events.first[:payload] # => { issue:, user:, timestamp:, ... }
Class Method Summary collapse
-
.capture ⇒ Array<Hash>
Events as { name: String, payload: Hash }.
Class Method Details
.capture ⇒ Array<Hash>
Returns events as { name: String, payload: Hash }.
188 189 190 191 192 193 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 188 def capture(&) events = [] callback = -> (name, _start, _finish, _id, payload) { events << { name: name, payload: payload } } ActiveSupport::Notifications.subscribed(callback, /^plan_my_stuff\./, &) events end |