Sha256: 41bd8b00e96deb75791cb03946b859bf0662150e1aa74ef6d460b296fa65652d

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module RSpec
      # Checks if examples are focused.
      #
      # @example
      #   # bad
      #   describe MyClass, focus: true do
      #   end
      #
      #   describe MyClass, :focus do
      #   end
      #
      #   fdescribe MyClass do
      #   end
      #
      #   # good
      #   describe MyClass do
      #   end
      class Focus < Base
        MSG = 'Focused spec found.'

        focused = ExampleGroups::FOCUSED + Examples::FOCUSED

        def_node_matcher :focusable_selector?,
                         (ExampleGroups::GROUPS + ExampleGroups::SKIPPED +
                          Examples::EXAMPLES + Examples::SKIPPED +
                          Examples::PENDING).node_pattern_union

        def_node_matcher :metadata, <<-PATTERN
          {(send #rspec? #focusable_selector? <$(sym :focus) ...>)
           (send #rspec? #focusable_selector? ... (hash <$(pair (sym :focus) true) ...>))}
        PATTERN

        def_node_matcher :focused_block?, focused.send_pattern

        def on_send(node)
          focus_metadata(node) do |focus|
            add_offense(focus)
          end
        end

        private

        def focus_metadata(node, &block)
          yield(node) if focused_block?(node)

          metadata(node, &block)
        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/focus.rb
rubocop-rspec-1.44.1 lib/rubocop/cop/rspec/focus.rb
rubocop-rspec-1.44.0 lib/rubocop/cop/rspec/focus.rb
rubocop-rspec-1.43.2 lib/rubocop/cop/rspec/focus.rb
rubocop-rspec-1.43.1 lib/rubocop/cop/rspec/focus.rb
rubocop-rspec-1.43.0 lib/rubocop/cop/rspec/focus.rb