Sha256: e7fede2db9bd0abb1350a7ca8be44c64a5c15902df1853afdc048903fe6c4c65

Contents?: true

Size: 1.51 KB

Versions: 9

Compression:

Stored size: 1.51 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
        include SkipOrPending

        MSG = 'Pending spec found.'

        # @!method skippable?(node)
        def_node_matcher :skippable?, <<~PATTERN
          {
            (send #rspec? #ExampleGroups.regular ...)
            (send nil? #Examples.regular ...)
          }
        PATTERN

        # @!method pending_block?(node)
        def_node_matcher :pending_block?, <<~PATTERN
          {
            (send #rspec? #ExampleGroups.skipped ...)
            (send nil? {#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

9 entries across 9 versions & 4 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/pending.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/pending.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/pending.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/pending.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.22.0/lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.22.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.21.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.20.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.19.0 lib/rubocop/cop/rspec/pending.rb