instance method assert_notifications_count

Ruby on Rails 8.1.2

Since v8.1.2

Signature

assert_notifications_count(pattern, count, &block)

Assert the number of notifications emitted with a given pattern.

You can assert the number of notifications emitted by passing a pattern, which accepts either a string or regexp, a count, and a block. While the block is executed, the number of matching notifications emitted will be counted. After the block’s execution completes, the assertion will pass if the count matches.

assert_notifications_count("post.submitted", 1) do
  post.submit(title: "Cool Post") # => emits matching notification
end

Parameters

pattern req
count req
block block
Source
# File activesupport/lib/active_support/testing/notification_assertions.rb, line 51
      def assert_notifications_count(pattern, count, &block)
        actual_count = capture_notifications(pattern, &block).count
        assert_equal(count, actual_count, "Expected #{count} instead of #{actual_count} notifications for #{pattern}")
      end

Defined in activesupport/lib/active_support/testing/notification_assertions.rb line 51 · 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