Sha256: 7cd637c19bb68948d3b708350e9f46754a30865a1fde9cfcae04fb2c36c1f2a4

Contents?: true

Size: 1.56 KB

Versions: 8

Compression:

Stored size: 1.56 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 < Cop
        MSG = 'Pending spec found.'

        PENDING = Examples::PENDING + Examples::SKIPPED + ExampleGroups::SKIPPED
        SKIPPABLE = ExampleGroups::GROUPS + Examples::EXAMPLES

        def_node_matcher :skippable?, SKIPPABLE.send_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?, PENDING.send_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

8 entries across 8 versions & 1 rubygems

Version Path
rubocop-rspec-1.42.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.41.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.40.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.39.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.38.1 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.38.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.37.1 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.37.0 lib/rubocop/cop/rspec/pending.rb