instance method assert_no_event_reported

Ruby on Rails 8.1.2

Since v8.1.2

Signature

assert_no_event_reported(name = nil, payload: {}, tags: {}, &block)

Asserts that the block does not cause an event to be reported to Rails.event.

If no name is provided, passes if evaluated code in the yielded block reports no events.

assert_no_event_reported do
  service_that_does_not_report_events.perform
end

If a name is provided, passes if evaluated code in the yielded block reports no events with that name.

assert_no_event_reported("user.created") do
  service_that_does_not_report_events.perform
end

Parameters

name opt = nil
payload key = {}
tags key = {}
block block
Source
# File activesupport/lib/active_support/testing/event_reporter_assertions.rb, line 101
      def assert_no_event_reported(name = nil, payload: {}, tags: {}, &block)
        events = EventCollector.record(&block)

        if name.nil?
          assert_predicate(events, :empty?)
        else
          matching_event = events.find { |event| event.matches?(name, payload, tags) }
          if matching_event
            message = "Expected no '#{name}' event to be reported, but found:\n  " \
              "#{matching_event.inspect}"
            flunk(message)
          end
          assert(true)
        end
      end

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

Defined in ActiveSupport::Testing::EventReporterAssertions

Type at least 2 characters to search.

↑↓ navigate · open · esc close