Sha256: 3bd1dc8f3d128f15c83560126a2515ab6a6acfcc5a20063d45401077c44bb0c5

Contents?: true

Size: 1.13 KB

Versions: 30

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # Checks for `assert_raises` with arguments of regular expression literals.
      # Arguments should be exception classes.
      # Optionally the last argument can be a custom message string to help explain failures.
      # Either way, it's not the argument that `exception.message` is compared to.
      # The raised exception is returned and can be used
      # to match against a regular expression.
      #
      # @example
      #
      #   # bad
      #   assert_raises FooError, /some message/ do
      #     obj.occur_error
      #   end
      #
      #   # good
      #   exception = assert_raises FooError do
      #     obj.occur_error
      #   end
      #   assert_match(/some message/, exception.message)
      #
      class AssertRaisesWithRegexpArgument < Base
        MSG = 'Do not pass regular expression literals to `assert_raises`. Test the resulting exception.'
        RESTRICT_ON_SEND = %i[assert_raises].freeze

        def on_send(node)
          add_offense(node) if node.last_argument&.regexp_type?
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
rubocop-minitest-0.36.0 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.35.1 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.35.0 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.34.5 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.34.4 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.34.3 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.34.2 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.34.1 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.34.0 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.33.0 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.32.2 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.32.1 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.32.0 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.31.1 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.31.0 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.30.0 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.29.0 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.28.0 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.27.0 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb
rubocop-minitest-0.26.1 lib/rubocop/cop/minitest/assert_raises_with_regexp_argument.rb