Sha256: 42c1e0c57f7cdcec73c6416fa05be0b2f8a27262e14ba68bb72a9f716d151cee

Contents?: true

Size: 930 Bytes

Versions: 2

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # Checks if test cases contain any assertion calls.
      #
      # @example
      #   # bad
      #   class FooTest < Minitest::Test
      #     def test_the_truth
      #     end
      #   end
      #
      #   # good
      #   class FooTest < Minitest::Test
      #     def test_the_truth
      #       assert true
      #     end
      #   end
      #
      class NoAssertions < Base
        include MinitestExplorationHelpers

        MSG = 'Test case has no assertions.'

        def on_class(class_node)
          return unless test_class?(class_node)

          test_cases(class_node).each do |node|
            assertions_count = assertions_count(node)

            next if assertions_count.positive?

            add_offense(node.block_type? ? node.loc.expression : node.loc.name)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-minitest-0.28.0 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.27.0 lib/rubocop/cop/minitest/no_assertions.rb