lib/rubocop/cop/rspec/focus.rb in rubocop-rspec-1.6.0 vs lib/rubocop/cop/rspec/focus.rb in rubocop-rspec-1.7.0
- old
+ new
@@ -1,11 +1,11 @@
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
- # Checks if test is focused.
+ # Checks if examples are focused.
#
# @example
# # bad
# describe MyClass, focus: true do
# end
@@ -18,39 +18,23 @@
#
# # good
# describe MyClass do
# end
class Focus < Cop
+ include RuboCop::RSpec::SpecOnly, RuboCop::RSpec::Language
+
MSG = 'Focused spec found.'.freeze
- FOCUSABLE_SELECTORS = '
- :context
- :describe
- :example
- :example_group
- :feature
- :it
- :scenario
- :specify
- :xcontext
- :xdescribe
- :xexample
- :xfeature
- :xit
- :xscenario
- :xspecify
- '.freeze
+ focusable =
+ ExampleGroups::GROUPS +
+ ExampleGroups::SKIPPED +
+ Examples::EXAMPLES +
+ Examples::SKIPPED
- FOCUSING_SELECTORS = '
- :fcontext
- :fdescribe
- :fexample
- :ffeature
- :fit
- :focus
- :fscenario
- :fspecify
- '.freeze
+ focused = ExampleGroups::FOCUSED + Examples::FOCUSED
+
+ FOCUSABLE_SELECTORS = focusable.to_node_pattern
+ FOCUSING_SELECTORS = focused.to_node_pattern
FOCUS_SYMBOL = s(:sym, :focus)
FOCUS_TRUE = s(:pair, FOCUS_SYMBOL, s(:true))
def_node_matcher :metadata, <<-PATTERN