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]    # => "issue_created.plan_my_stuff"
events.first[:payload] # => { issue:, user:, timestamp:, ... }

Class Method Summary collapse

Class Method Details

.captureArray<Hash>

Returns events as { name: String, payload: Hash }.

Returns:

  • (Array<Hash>)

    events as { name: String, payload: Hash }



196
197
198
199
200
201
# File 'lib/plan_my_stuff/test_helpers.rb', line 196

def capture(&)
  events = []
  callback = -> (name, _start, _finish, _id, payload) { events << { name: name, payload: payload } }
  ActiveSupport::Notifications.subscribed(callback, /\.plan_my_stuff\z/, &)
  events
end