From cfb46fe4b0ed216d2b1503ed7753213a70dd8f65 Mon Sep 17 00:00:00 2001 From: Jerome Dalbert Date: Sat, 23 Apr 2022 13:30:34 -0700 Subject: [PATCH] Compute file path with ActiveSupport Inflector if defined --- lib/rubocop/cop/rspec/file_path.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/rubocop/cop/rspec/file_path.rb b/lib/rubocop/cop/rspec/file_path.rb index c2ab8f584..4a5848ea0 100644 --- a/lib/rubocop/cop/rspec/file_path.rb +++ b/lib/rubocop/cop/rspec/file_path.rb @@ -130,6 +130,13 @@ def expected_path(constant) end def camel_to_snake_case(string) + if defined?(ActiveSupport::Inflector) + if File.exist?('./config/initializers/inflections.rb') + require './config/initializers/inflections' + end + return ActiveSupport::Inflector.underscore(string) + end + string .gsub(/([^A-Z])([A-Z]+)/, '\1_\2') .gsub(/([A-Z])([A-Z][^A-Z\d]+)/, '\1_\2')