Sha256: 62ff3d84bf69e52b8ea4313342464476c5bd7d20b5cc840a6043f2bebfde8b7e

Contents?: true

Size: 1.09 KB

Versions: 15

Compression:

Stored size: 1.09 KB

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

        private

        def assertions_count(node)
          base = assertion_method?(node) ? 1 : 0
          base + node.each_child_node.sum { |c| assertions_count(c) }
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rubocop-minitest-0.26.1 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.26.0 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.25.1 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.25.0 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.24.0 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.23.2 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.23.1 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.23.0 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.22.2 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.22.1 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.22.0 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.21.1 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.21.0 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.20.1 lib/rubocop/cop/minitest/no_assertions.rb
rubocop-minitest-0.20.0 lib/rubocop/cop/minitest/no_assertions.rb