Sha256: 08bf52bb4ff16199fafecc1b93659df9d0ac20f9a2d033e5eedc8a64a785f3d6

Contents?: true

Size: 1.4 KB

Versions: 19

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # Detects non `public` (marked as `private` or `protected`) test methods.
      # Minitest runs only test methods which are `public`.
      #
      # @example
      #   # bad
      #   class FooTest
      #     private # or protected
      #     def test_does_something
      #       assert_equal 42, do_something
      #     end
      #   end
      #
      #   # good
      #   class FooTest
      #     def test_does_something
      #       assert_equal 42, do_something
      #     end
      #   end
      #
      #   # good (not a test case name)
      #   class FooTest
      #     private # or protected
      #     def does_something
      #       assert_equal 42, do_something
      #     end
      #   end
      #
      #   # good (no assertions)
      #   class FooTest
      #     private # or protected
      #     def test_does_something
      #       do_something
      #     end
      #   end
      #
      class NonPublicTestMethod < Base
        include MinitestExplorationHelpers
        include DefNode

        MSG = 'Non `public` test method detected. Make it `public` for it to run.'

        def on_class(node)
          test_cases(node, visibility_check: false).each do |test_case|
            add_offense(test_case) if non_public?(test_case) && assertions(test_case).any?
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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