instance method capture_notifications

Ruby on Rails 8.1.2

Since v8.1.2

Signature

capture_notifications(pattern = nil, &block)

Capture emitted notifications, optionally filtered by a pattern.

You can capture emitted notifications, optionally filtered by a pattern, which accepts either a string or regexp, and a block.

notifications = capture_notifications("post.submitted") do
  post.submit(title: "Cool Post") # => emits matching notification
end

Parameters

pattern opt = nil
block block
Source
# File activesupport/lib/active_support/testing/notification_assertions.rb, line 85
      def capture_notifications(pattern = nil, &block)
        notifications = []
        ActiveSupport::Notifications.subscribed(->(n) { notifications << n }, pattern, &block)
        notifications
      end

Defined in activesupport/lib/active_support/testing/notification_assertions.rb line 85 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::Testing::NotificationAssertions

Type at least 2 characters to search.

↑↓ navigate · open · esc close