Sha256: ec6302b05766c1b55b3313f6bcc7f3b7fff38ff8d23075d60c41f24f6abed1ab

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks for any pending or skipped examples.
      #
      # @example
      #   # bad
      #   describe MyClass do
      #     it "should be true"
      #   end
      #
      #   describe MyClass do
      #     it "should be true", skip: true do
      #       expect(1).to eq(2)
      #     end
      #   end
      #
      #   describe MyClass do
      #     it "should be true" do
      #       pending
      #     end
      #   end
      #
      #   describe MyClass do
      #     xit "should be true" do
      #     end
      #   end
      #
      #   # good
      #   describe MyClass do
      #   end
      class Pending < Base
        MSG = 'Pending spec found.'

        def_node_matcher :skippable?,
                         send_pattern(<<~PATTERN)
                           {#ExampleGroups.regular #Examples.regular}
                         PATTERN

        def_node_matcher :skipped_in_metadata?, <<-PATTERN
          {
            (send _ _ <#skip_or_pending? ...>)
            (send _ _ ... (hash <(pair #skip_or_pending? { true str }) ...>))
          }
        PATTERN

        def_node_matcher :skip_or_pending?, '{(sym :skip) (sym :pending)}'

        def_node_matcher :pending_block?,
                         send_pattern(<<~PATTERN)
                           {
                             #ExampleGroups.skipped
                             #Examples.skipped
                             #Examples.pending
                           }
                         PATTERN

        def on_send(node)
          return unless pending_block?(node) || skipped?(node)

          add_offense(node)
        end

        private

        def skipped?(node)
          skippable?(node) && skipped_in_metadata?(node)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-rspec-2.2.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.1.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.0.1 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.0.0 lib/rubocop/cop/rspec/pending.rb