lib/rubocop/cop/rspec/file_path.rb in rubocop-rspec-1.5.1 vs lib/rubocop/cop/rspec/file_path.rb in rubocop-rspec-1.5.2
- old
+ new
@@ -1,6 +1,5 @@
-# encoding: utf-8
# frozen_string_literal: true
module RuboCop
module Cop
module RSpec
@@ -27,29 +26,28 @@
return unless single_top_level_describe?
object = args.first.const_name
return unless object
- path_matcher = matcher(object, args[1])
+ path_matcher = matcher(object, args.at(1))
return if source_filename =~ regexp_from_glob(path_matcher)
add_offense(node, :expression, format(MESSAGE, path_matcher))
end
private
def routing_spec?(args)
- args[1..-1].any? do |arg|
- next unless arg.hash_type?
+ args.any? do |arg|
arg.children.include?(ROUTING_PAIR)
end
end
def matcher(object, method)
path = File.join(parts(object))
- if method && method.type == :str
- path += '*' + method.children.first.gsub(/\W+/, '')
+ if method && method.type.equal?(:str)
+ path += '*' + method.str_content.gsub(/\W+/, '')
end
"#{path}*_spec.rb"
end
@@ -62,22 +60,21 @@
def source_filename
processed_source.buffer.name
end
def camel_to_underscore(string)
- string.dup.tap do |result|
- result.gsub!(/([^A-Z])([A-Z]+)/, '\\1_\\2')
- result.gsub!(/([A-Z])([A-Z\d][^A-Z\d]+)/, '\\1_\\2')
- result.downcase!
- end
+ string
+ .gsub(/([^A-Z])([A-Z]+)/, '\\1_\\2')
+ .gsub(/([A-Z])([A-Z\d][^A-Z\d]+)/, '\\1_\\2')
+ .downcase
end
def regexp_from_glob(glob)
- Regexp.new(glob.gsub('.', '\\.').gsub('*', '.*') + '$')
+ Regexp.new(glob.sub('.', '\\.').gsub('*', '.*') + '$')
end
def custom_transform
- cop_config['CustomTransform'] || []
+ cop_config['CustomTransform'] || {}
end
end
end
end
end