Sha256: 84df54e494c0ec8f0e712c590b8059d75f5fe4e7815f93fee6bbba94787569bf

Contents?: true

Size: 1.56 KB

Versions: 6

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 < Base
        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

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-rspec-2.0.0.pre lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.44.1 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.44.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.43.2 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.43.1 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-1.43.0 lib/rubocop/cop/rspec/pending.rb