method

capture_error_reports

rails latest stable - Class: ActiveSupport::Testing::ErrorReporterAssertions

Method not available on this version

This method is only available on newer versions. The first available version (v8.1.1) is shown here.

capture_error_reports(error_class = StandardError, &block)
public

Captures reported errors from within the block that match the given error class.

reports = capture_error_reports(IOError) do
  Rails.error.report(IOError.new("Oops"))
  Rails.error.report(IOError.new("Oh no"))
  Rails.error.report(StandardError.new)
end

assert_equal 2, reports.size
assert_equal "Oops", reports.first.error.message
assert_equal "Oh no", reports.last.error.message