lib/rubocop/cop/rspec/cop.rb in rubocop-rspec-1.20.1 vs lib/rubocop/cop/rspec/cop.rb in rubocop-rspec-1.21.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module RuboCop
module Cop # rubocop:disable Style/Documentation
WorkaroundCop = Cop.dup
# Clone of the the normal RuboCop::Cop::Cop class so we can rewrite
@@ -40,10 +42,15 @@
include RuboCop::RSpec::Language::NodePattern
DEFAULT_CONFIGURATION =
RuboCop::RSpec::CONFIG.fetch('AllCops').fetch('RSpec')
+ DEFAULT_PATTERN_RE = Regexp.union(
+ DEFAULT_CONFIGURATION.fetch('Patterns')
+ .map(&Regexp.public_method(:new))
+ )
+
# Invoke the original inherited hook so our cops are recognized
def self.inherited(subclass)
RuboCop::Cop::Cop.inherited(subclass)
end
@@ -56,15 +63,28 @@
def relevant_rubocop_rspec_file?(file)
rspec_pattern =~ file
end
def rspec_pattern
- Regexp.union(rspec_pattern_config.map(&Regexp.public_method(:new)))
+ if rspec_pattern_config?
+ Regexp.union(rspec_pattern_config.map(&Regexp.public_method(:new)))
+ else
+ DEFAULT_PATTERN_RE
+ end
end
- def rspec_pattern_config
+ def all_cops_config
config
.for_all_cops
+ end
+
+ def rspec_pattern_config?
+ return unless all_cops_config.key?('RSpec')
+ all_cops_config.fetch('RSpec').key?('Patterns')
+ end
+
+ def rspec_pattern_config
+ all_cops_config
.fetch('RSpec', DEFAULT_CONFIGURATION)
.fetch('Patterns')
end
end
end