Sha256: 07af17b4ca5432d7bd3c8605af586b7a05a8dc679126bb1c3d9e7c78b3907470

Contents?: true

Size: 1.33 KB

Versions: 9

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 < Cop
        MSG = 'Focused spec found.'

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

        focused = ExampleGroups::FOCUSED + Examples::FOCUSED

        FOCUSABLE_SELECTORS = focusable.node_pattern_union

        def_node_matcher :metadata, <<-PATTERN
          {(send #{RSPEC} #{FOCUSABLE_SELECTORS} <$(sym :focus) ...>)
           (send #{RSPEC} #{FOCUSABLE_SELECTORS} ... (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

9 entries across 9 versions & 1 rubygems

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