instance method assert_raises

Ruby on Rails 8.1.2

Since v7.1.6

Available in: v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

assert_raises(*exp, match: nil, &block)

Asserts that a block raises one of exp. This is an enhancement of the standard Minitest assertion method with the ability to test error messages.

assert_raises(ArgumentError, match: /incorrect param/i) do
  perform_service(param: 'exception')
end

Parameters

exp rest
match key = nil
block block
Source
# File activesupport/lib/active_support/testing/assertions.rb, line 34
      def assert_raises(*exp, match: nil, &block)
        error = super(*exp, &block)
        assert_match(match, error.message) if match
        error
      end

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

Defined in ActiveSupport::Testing::Assertions

Type at least 2 characters to search.

↑↓ navigate · open · esc close