Sha256: c2e6b81431d082928366811dd78501a82a745679389fb0a92851186bd7bb30f9

Contents?: true

Size: 1.83 KB

Versions: 24

Compression:

Stored size: 1.83 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 ...)
            #skippable_example?
          }
        PATTERN

        # @!method skippable_example?(node)
        def_node_matcher :skippable_example?, <<~PATTERN
          (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)) ||
            skipped_regular_example_without_body?(node)
        end

        def skipped_regular_example_without_body?(node)
          skippable_example?(node) && !node.block_node
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 5 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.3/lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-3.3.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-3.2.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-3.1.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-3.0.5 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-3.0.4 lib/rubocop/cop/rspec/pending.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-3.0.3 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-3.0.2 lib/rubocop/cop/rspec/pending.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rspec-3.0.1/lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-3.0.1 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-3.0.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-3.0.0.pre lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.31.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.30.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.29.2 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.29.1 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.29.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.28.0 lib/rubocop/cop/rspec/pending.rb
rubocop-rspec-2.27.1 lib/rubocop/cop/rspec/pending.rb