Sha256: 7c999f7c7e172bbe985477460b989c3fa450b95224f475f1c989155283ec72f8

Contents?: true

Size: 1.52 KB

Versions: 24

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # Checks for skipped tests missing the skipping reason.
      #
      # @example
      #   # bad
      #   skip
      #   skip('')
      #
      #   # bad
      #   if condition?
      #     skip
      #   else
      #     skip
      #   end
      #
      #   # good
      #   skip("Reason why the test was skipped")
      #
      #   # good
      #   skip if condition?
      #
      class SkipWithoutReason < Base
        MSG = 'Add a reason explaining why the test is skipped.'

        RESTRICT_ON_SEND = %i[skip].freeze

        def on_send(node)
          return if node.receiver || !blank_argument?(node)

          conditional_node = conditional_parent(node)
          return if conditional_node && !only_skip_branches?(conditional_node)

          return if node.parent&.resbody_type?

          add_offense(node)
        end

        private

        def blank_argument?(node)
          message = node.first_argument
          message.nil? || (message.str_type? && message.value == '')
        end

        def conditional_parent(node)
          return unless (parent = node.parent)

          if parent.if_type? || parent.case_type?
            parent
          elsif parent.when_type?
            parent.parent
          end
        end

        def only_skip_branches?(node)
          branches = node.branches.compact
          branches.size > 1 && branches.all? { |branch| branch.send_type? && branch.method?(:skip) }
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

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